How to make an actor follow a mouse click.

bgjoanbgbgjoanbg Member Posts: 17
edited November -1 in Working with GS (Mac)
Hi, I'm trying to make an actor go to the position where where a mouse click was executed. Right now when I click, the actor goes to the mouse position, not were the click was executed.
I have a rule which says:
If the mouse click is executed and the mouse position (X and Y) is outside the actor, MOVE TO mouse position.
Is there anyway I can make it go to the click?
Please help.

Comments

  • ORBZORBZ Member Posts: 1,304
    capture the x and y position of the click using a change attribute behavior, store those values on two actor variables. move to the stored position.

    rule when mouse down

    change attribute self.savedX = mouse.poisition.x
    change attribute self.savedY = mouse.position.y

    moveTo(self.savedX, self.savedY)

    Additionally, see my example here for a whole other way of doing it completely unrelated to the above example, but also really good for seeing how there is more than one way to skin a cat. The example below uses vectors and distance and time.

    http://gamesalad.com/game/play/76525
Sign In or Register to comment.