Constrain actor position relative to touch position?

olster1olster1 Member Posts: 396
edited November -1 in Working with GS (Mac)
Hey guys, I totally thought I could figure this out in my head or find a similar project but I cant.

So basically I need a set of rules and attributes to make a an actor follow a touch position relative to the first touch. If that makes sense.

In other words, if I touched the screen 200 pixels to the right and 40 pixels higher than the actor and then dragged my finger, the actor would move relative to it.

Any help is appreciated.

Thanks

Olivier

Comments

  • POMPOM Member Posts: 2,599
    Try this :
    create 2 self real attributes :
    offset x .
    offset y

    in your actor make this:
    when mouse button is down -
    change self.offsetX to - self.position.X - mouse.position.X
    change self.offsetY to - self.position.Y - mouse.position.Y

    Constrain self.position.X to mouse.position.X+self.offsetX
    Constrain self.position.Y to mouse.position.Y+self.offsetY

    I think this should work .

    Roy.
  • olster1olster1 Member Posts: 396
    thanks, it's almost there, not doing it perfectly though. You have set me off in the right direction so thank you. :)
  • olster1olster1 Member Posts: 396
    Probably my bad but after drawing some things in my head and on paper there was no need for the first minus sign in "- self.position.X - mouse.position.X" It may just have been me misreading it but anyway its all good now and works great!

    Thanks :D
Sign In or Register to comment.