How do I move 16 pixels in one direction?

0 favourites
  • 6 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • Hey. I need to move a character 16 pixels in the direction I press, but I don't want him to just snap to the new position like he does with the 'set X' command, I need to see the character move, but he has to stop at exactly 16 pixels from where he started.

    Can anyone help me with this one? Thanks.

  • You can do it with bullet behaviour or manually, and comparing position with a variable, i dont know if there is an easier wayt to o it, for the moment i would try that

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • There are many ways to do it. Basically if you want to move a character from point A to point B in X seconds then your have to draw the position change across some amount of frames. If you just use Set X then it will move it in one frame.

    You can use "lerp" function, then you can do a nice smooth animation. You can use "every tick" or "Every X seconds" and change character's position every frame. In both cases you simply check if currentPosition - startingPosition = 16, and if so then stop it.

    You can also use a Platform behaviour, and move character with built in functions.... and many other ways. It's all about your creativity .

  • You could use the behavior-plugin from rexrainbow.

    http://c2rexplugins.weebly.com/rex_moveto.html

  • Excellent stuff, lads. Thanks! I'll give it a go.

  • I have some math that may help. You can set X Y through this equation. All you need is and angle and a distance. The rest is trigonometry.

    left arrow is pressed

    targetY = Sprite.X + d * cos(180)

    targetX = Sprite.Y + d * sin(180)

    down arrow is pressed

    targetY = Sprite.X + d * cos(90)

    targetX = Sprite.Y + d * sin(90)

    as you can see you are only changing the angle. If I were you I would save this. This will allow you to pick a point, from any sprite, move a sprite to it, or move that sprite to it.. Move ant sprite, any distance, in any direction.

    Swap d out for distance.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)