Moving an actor/changing directions/where touch is pressed. HELP?!

This may be a bit ambitious, but I would really love some advice on how to make this happen :)

I want the main actor to move according to where touch is pressed on the screen. I have animations for my actor to move in all 4 directions. So if the touch is pressed to the left of the actor, I want the left animation to activate while moving the actor to the left. And so on.

But here is where my true problem comes in. If touch is pressed at an angle of the actor I want the actor to move in an L shape vs in the angle of the touch and I want the animations to go along with the direction the actor is moving in. So if touch is pressed up-left of the actor, the actor will move left (with the left animation) and then up (with the up animation). Then if touch is pressed again while the actor is still moving from the previous touch, I want it to go towards the new touch instead.

If anyone can help that would be just peaches :) Thank you.

Comments

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited September 2013
    You might want to put a bit more into it but here's the basics on how I'd do it. Click anywhere on the screen and it will move along the x axis to the mouse and then along the y axis.

    What you might want to do is change the speed of the interpolate based on the distance it's travelling a long one axis because at the moment it takes 0.5 seconds to travel the line regardless of how long the line is and on a short line it will move slowly.

    EDIT: I've noticed a problem where if you move the mouse while it's moving it changes direction so have deleted it and uploaded a new version in the post below

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited September 2013
    This one is a little better and doesn't change direction when you move the mouse.

    It uses an invisible actor over the scene which I've called Trackpad. When it's pressed it stores the x and y position of the mouse/touch in two game attributes, and then moves the character to those values.

    It only took like 2 seconds to create so it's not a problem if it's not what you're after :)

    EDIT: I updated it some more and attached a new version in the post below.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    New version attached that moves at a constant pace regardless of the distance it travels, and shows in a text display what direction the character is moving which you could use to change your animations accordingly.
Sign In or Register to comment.