Animate when there is a change in self.positionX

Hello

I have an actor following the movement of a touch on X axis. It basically constraints its position.X to touch.1.X

Im having a problem animating this actor. Im trying to animate when the actor changes its position(move), either left or right.
I've been trying to figure this out for a week now. So far, I got two different approaches. First one, the actor moves just like i want, it moves smooth but doesn't animate correctly. My second approach, the actor animates just perfect, but doesn't move smooth (It doesn't mimic the movement of the touch)


This is the first approach game project, please take a look.
In the project, as you can see the animation won't stop when the actor stops.
https://www.dropbox.com/sh/h36vs3u483pxm52/Qn6vV9ybUx

With another approach I got everything working, it animates perfect. However, with this approach, it doesn't exactly mimics the swipe of the finger like in the first project.

This is the second approach game project.
https://www.dropbox.com/sh/kxf2w10t6rrq398/KiciDlLSKs

Take a look at both and you will see the differences of the movements.

Thank you!!

Answers

  • carlblanchetcarlblanchet Member Posts: 755
    Have you tried comparing the self.position.x and the touch.1.x ?

    If the touch.1.x is greater than self.position.x you know it will be going right, and if the touch.1.x is less than self.position.x you know it will be going left.

    From this info you can tell the animation to animate left or right.
  • fozkulfozkul Member Posts: 27
    thanks for the respond @carlblanchet . I have tried that already. With that method, it doesn't animate correctly
  • fozkulfozkul Member Posts: 27
    BUMP
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    What kind of movement do you want the actor to have? For instance, do you want it to walk to the touch.X at a steady pace -- then stop? Perhaps you want it to walk at a steady speed but the speed is adjusted to the initial distance between the actor and the touch.X? Or do you want it to start fast and slow down as it approaches touch.X? Or do you want it to simply jump to touch.X and then update to touch.X constantly (like the first example)?

    The more detail you give the easier it is to describe what needs to be done.
  • fozkulfozkul Member Posts: 27
    hello @RThurman Thanks for the respond. I Basically, I want my actor to mimic the same movement of the touch. Let's say I touched anywhere on the screen and drag my finger, I want my actor to follow the finger at exact speed with the dragging. I actually got it moving as i wanted. I do not have any problem with moving the actor.

    My problem is the animation. I don't know if you have seen the animation on the first example, it is not working right ( Actually I couldn't implement it right). The animation is not working smooth as the second project.

    On the second project, the actor animates perfect but it doesn't really follow the finger, it constraints speed of the touch instead of its position.

    So what i really wanna do is, I want my actor to move as in 1st project and animate like in the 2nd project.

    Thanks Again!!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    OK -- Give this a try:

    Make an attribute (type=real): oldX

    When game.Touches.Count = 1
    -- Animate Behavior
    -- Timer every 0 seconds
    ---- Change Attribute self.Position.X To: game.Touches.Touch 1.X
    ---- When game.Touches.Touch 1.X > self.oldX
    ------ Change Attribute self.Graphics.Flip Horizontally To: false
    ------ Change Attribute self.oldX To: game.Touches.Touch 1.X
    ---- When game.Touches.Touch 1.X < self.oldX
    ------ Change Attribute self.Graphics.Flip Horizontally To: true
    ------ Change Attribute self.oldX To: game.Touches.Touch 1.X
  • fozkulfozkul Member Posts: 27
    hi, thanks for the respond

    it partially works.
    It keeps animating as long as the touch is pressed still.
    I actually want to animate when there is a position change
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited October 2012
    Oh -- OK try this:

    Animate Behavior
    Timer every 0 seconds
    --Change Attribute self.Position.X To: game.Mouse.Position.X
    --When game.Mouse.Position.X > self.oldX
    ----Change Attribute self.Graphics.Flip Horizontally To: false
    ----Change Attribute self.oldX To: game.Mouse.Position.X
    --When game.Mouse.Position.X < self.oldX
    ----Change Attribute self.Graphics.Flip Horizontally To: true
    ----Change Attribute self.oldX To: game.Mouse.Position.X
  • fozkulfozkul Member Posts: 27
    Hi @Rthurman Thanks for helping me out.

    This time it animates when it stands still. So I think I have to put this animate behavior into some kind of a rule
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited October 2012
    Lets try this:

    Constrain Attribute: self.Motion.Linear Velocity.X To:(game.Mouse.Position.X-self.Position.X)*25
    When self.Motion.Linear Velocity.X > 3
    -- Animate Right
    When self.Motion.Linear Velocity.X < -3
    -- Animate Left
    When self.Motion.Linear Velocity.X >-3 (AND) self.Motion.Linear Velocity.X < 3
    -- Change image (monkey_1)

    I think this is closer to having the monkey stand still like you want.
  • fozkulfozkul Member Posts: 27
    Thanks. That works :)

    But i have another problem with this

    My actor is collidable with some other actors, when it collides it's gonna make my actor bounce. I want it to be stable. That's why i was trying to implement with position change instead of velocity change, so I could set it to not movable.

    But i guess with this method, i can just give a density of 5000+, so my actor wont move when it collides with my other actors.

    Thanks a bunch!!!
Sign In or Register to comment.