Smooth drag actor movement effect?
justinodunn
Member, PRO Posts: 226
Hey guys, I made an actor that can be dragged to whatever position on the screen. So I did when touched, constrain attribute self position x and y to mouse position x and y. It works, but the movement is very "instantaneous" and "rapid". Any ideas how to make it so when I drag the actor across the screen, it is slightly delayed so it creates sort of a smooth looking movement?
Comments
When Touch is pressed
--Constrain Linear Velocity X to 5* ( game.Mouse.Position.X - self.Position.X )
--Constrain Linear Velocity Y to 5* ( game.Mouse.Position.Y - self.Position.Y )
. . . and if you also want rotation . . .
--Constrain Rotation to vectorToAngle( self.Motion.Linear Velocity.X , self.Motion.Linear Velocity.Y )
P.S . . . if you don't want the actor to float off . . . (just tested the above code !!) . . then when using the above rule have the actor slow to a halt when the touch is released, you can do this by placing a change attribute behaviour in the Otherwise section like this . . .
Otherwise
--Change Drag to 1000
(adjust the drag coefficient to whatever suits your needs)
Awesome! Seems to work well. Can you please explain why its game mouse position - self position?
As the actor nears the mouse position the mathematical calculation: target position - current position grows ever smaller, so when the actor reaches the target position the the calculation produces 0 . . . . does that make sense ? Take a look at the calculation logically, it's saying something fairly basic / simple.
Ah got it, thanks!
I posted a few other options in this previous thread:
http://forums.gamesalad.com/discussion/comment/560789#Comment_560789
They all do the same thing, smooth out the mechanical feel of directly dragging an actor, but all feel a little different from each other.
Or you can set max velocity to zero and switch it on and off.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS