Set Velocity towards a point

akn320akn320 Member Posts: 1
edited November -1 in Working with GS (Mac)
given an input (like mouse or touch x/y coordinates), I want to have an object move, with a set velocity, towards those coordinates.
This would be similar to the "Move to" action, except it wouldn't stop once it got there.
How do i do this?
Thanks

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi akn320, the following method will do what your after:

    Firstly, you'll need an actor to cover the complete screen area, call it Actor1 (original!)

    The object you want to move to the touch/mouse position I'll call Actor2

    In the Rules of Actor1, put the following:
    Interpolate>Interpolate Attribute: scene:Background.Actor1.Position.X To game.Touches.touch 1.X. Set your duration, 0.1 for instance, perhaps experiment with the function then:

    Repeat all of that with another Interpolate, except change both to end with Y.

    PS hang on, just reread your post; you want it to carry on...I'll try to figure it out and let you know, unless someone else beats me to it!

    I would have deleted this, but you can't delete your own posts in this Forum, as you know...

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Sorry, tried to help but couldn't work it out. :-(

    Not sure how keep it moving at the same angle past the touch point. You'd need Move, one each after the Interpolates, but I don't know how to get the angle info for its direction, based on its starting point as the centre and its finishing point, the angle made there, if you get my drift. Hope someone can point you in the right direction. (if you excuse the pun!).

    Edit: Actually, just thought of a clumsy way to do it but which will work; OK, maybe not clumsy, just a workaround:

    In the two Interpolate Behaviours where you're putting game.touches.touch 1.x, and the same with y on the end, for both add +500. Should carry on then, outside of the screen.

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Use vectorToAngle in the angle box of an acceleration behavior, but put this in a timer so that it is accelerating towards the x,y coordinates for just a short time and then it will continue on (depending on how you set drag)

    Or you could try an accelerate towards behavior in a timer. If you don't use the timer it will not go past the point.
  • ORBZORBZ Member Posts: 1,304
    rule: touch.count > 0
    accelerate towards coord-x, coord-y (scene)

    -- or if you want a fixed velocity --

    -- calculate the angle to the new position:

    theta = vectorToAngle(destX - self.position.x, destY - self.position.y)

    rule: touch.count > 0
    move angle: theta (scene), speed 100
Sign In or Register to comment.