Set Velocity towards a point
akn320
Member Posts: 1
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
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
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
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
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.
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