How do I move 16 pixels in one direction?

Get help using Construct 2

Post » Mon Sep 07, 2015 11:01 am

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.
B
7
S
2
Posts: 60
Reputation: 604

Post » Mon Sep 07, 2015 11:11 am

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
B
22
S
9
G
4
Posts: 66
Reputation: 3,775

Post » Mon Sep 07, 2015 11:21 am

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 :).
ImageImageImage
B
27
S
16
G
74
Posts: 985
Reputation: 41,689

Post » Mon Sep 07, 2015 11:25 am

You could use the behavior-plugin from rexrainbow.
http://c2rexplugins.weebly.com/rex_moveto.html
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

Post » Mon Sep 07, 2015 11:44 am

Excellent stuff, lads. Thanks! I'll give it a go.
B
7
S
2
Posts: 60
Reputation: 604

Post » Mon Sep 07, 2015 1:01 pm

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.
B
7
S
2
Posts: 92
Reputation: 663


Return to How do I....?

Who is online

Users browsing this forum: Leef, tarek2 and 25 guests