Change animation based on finger drag?

Quick question. I have been trying to figure out how to do this to no avail. I have an actor that is controlled by two buttons left and right, the actor moves left and right depending on which is pressed and he also has corresponding animations for left and right... easy.

but..
I decided that I want a 1 finger touch slide controls for left and right, so I constrained the actor to another so that instead of pressing 2 buttons you can slide your finger back and forth to control right left movement.

The problem: How do I get my right, left animations to work with this slide control? So that when you slide left his left animations work, and when you slide right his right animations work...

Any help as always is greatly appreciated!
Rob

Comments

  • PixelPunPixelPun Member Posts: 324
    I realize its been only a few hours, there has to be a way to do this that I am not thinking of. I have been working on this for about 4 hours and cannot figure this thing out.

    Maybe if I ask in a different way?

    Is there a way to use counting up and down as a trigger for something (like my animations) So that when ship is being dragged right the right animations fire... and if dragged left the left animations go. I thought maybe this could be done with the X position of the actor... but I couldn't get that to work.

    There has to be a way to do this right?
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited August 2013
    Could it be as simple as setting up a game attribute called Direction. And when the player is going left change the value of direction to Left, and then change it to Right when the player is going right.

    Then have a rule with that says something like.

    if Direction is Left

    Play the left animation

    Otherwise

    Play the right animation


    Just a thought...


    As I type that out I'm also thinking you could just check the value of your Linear.Velocity X in two rules, like this:

    If Linear.Velocity X > 0 (that's moving right)

    Play the right animation

    and do a second rule that says:

    If Linear.Velocity X < 0 (that's moving left)

    Play the left animation
  • PixelPunPixelPun Member Posts: 324
    See, I want to say I tried that... but I could never get the linear.velocity to show up anything other than zero? Could this because I have the actor constrained to another actor so that the drag works? I wanted the player to be able to see the actor so I constrained it to another so that you can drag under the actor.
  • PixelPunPixelPun Member Posts: 324
    Well searching around I found out that constrain is not viewed as movement by the physics engine... So not sure where to go from here... o well.
  • ericzingelerericzingeler Member Posts: 334
    edited August 2013
    I assume you're trying to constrain an actor's position and thus why physics isn't working.

    Use the following if you'd like to constrain an actors movement to another:

    constrain linear.velocity.x To: (target.pos.x - self.pos.x)*20

    Then do the same for y-axis.

    Constrain is just a behavior that continually changes an attribute as fast as programmatically possible. Basically, a never ending change attribute. Constrain is in no way related to the physics engine.

    Physics wasn't working because you were constraining an actor's position. Moving an actor and changing its position are not the same. A position of an actor is nothing more than its x and y coordinates.

    Movement of an actor includes information such as position, acceleration, velocity, vector and so on. This information needs to be present for physics to function properly.

    Editing an actors position will always disrupt physics.

    Remember, there is nothing magical going on behind the scenes... it's all math. ;)
  • PixelPunPixelPun Member Posts: 324
    :P Well that explains it then... I'm horrible at math.... lol. Thanks for the help! Going to try this out!
  • PixelPunPixelPun Member Posts: 324
    Ok... that worked.. ^:)^ thank you so much!
Sign In or Register to comment.