Smooth drag actor movement effect?

justinodunnjustinodunn 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

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2016

    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 )

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2016

    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)

  • justinodunnjustinodunn Member, PRO Posts: 226

    Awesome! Seems to work well. Can you please explain why its game mouse position - self position?

  • SocksSocks London, UK.Member Posts: 12,822

    @justinodunn said:
    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.

  • justinodunnjustinodunn Member, PRO Posts: 226

    Ah got it, thanks! :)

  • SocksSocks London, UK.Member Posts: 12,822

    @justinodunn said:
    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.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @Socks said:
    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)

    Or you can set max velocity to zero and switch it on and off.

Sign In or Register to comment.