How do I get the angle at which a sprite is moving?

Get help using Construct 2

Post » Wed Jan 28, 2015 10:05 am

Hello, My name is Ben and I find this game engine to be awesome! :D

I am making a shoot 'em up game and I have a sprite that gets moved when a user "is in touch".

My question is, how do I get the angle value that the sprite is heading to?

I have tried making a compass with an object in the middle of the screen and an object bar on the sprite (which pointed to the object on the centre of screen) but that did not work well.

Is there an easier way to get the angle?
B
3
Posts: 7
Reputation: 191

Post » Wed Jan 28, 2015 11:51 am

Hi Benydc,

you can get the angle of an object via the expression panel.
Like:

Event: Every Tick

Action: Set global variable to...
Then a dialog pops open where you can set the value. Plus the expression
panel opens up. If you click into the value field you can select the object from
the expressions panel. The first expression in this list is "Angle" (Get the
object´s current angle, in degrees).
Hope that helps.

Greetings
Soulsliver
B
5
S
1
G
1
Posts: 22
Reputation: 1,069

Post » Wed Jan 28, 2015 1:01 pm

Hello Soulsliver,

I have tried that before but it only gets the angle of which the sprite is rotated at. (it is set to 270 degrees so it will always point to that)

Check attachment for example.
You do not have the required permissions to view the files attached to this post.
B
3
Posts: 7
Reputation: 191

Post » Wed Jan 28, 2015 1:39 pm

Create 2 instance variables on the object called something like PreviousX and PreviousY

On start of layout
--- Set Object.PreviousX to Object.X
--- Set Object.PreviousY to Object.Y

Every tick
--- Angle of Motion = angle(Object.PreviousX, Object.PreviousY, Object.X, Object.Y)
--- Set Object.PreviousX to Object.X
--- Set Object.PreviousY to Object.Y
B
62
S
19
G
8
Posts: 341
Reputation: 12,075

Post » Wed Jan 28, 2015 2:15 pm

That has worked!

Thank you zatyka!

Ben C.
B
3
Posts: 7
Reputation: 191


Return to How do I....?

Who is online

Users browsing this forum: htmlgames and 4 guests