Physics - How do I get Angle of Motion?

Get help using Construct 2

» Sat Nov 22, 2014 4:40 pm

I'm trying to get the angle of motion of a physics object.

I've tried:
Code: Select all
angle(0,0,sprite.Physics.VelocityX,sprite.Physics.VelocityY)

But sometimes I get a negative number. Am I doing this correctly? Or is there something I need to do to convert the negative?
B
34
S
10
G
5
Posts: 165
Reputation: 6,707

» Sat Nov 22, 2014 6:53 pm

I noticed this recently as well. Does the physics object have any joints on it? I'm wondering if the joints are affecting the value.
Perhaps you can record the last position it was at (in the previous event cycle), and calculate the current trajectory based on that?
B
49
S
23
G
66
Posts: 1,151
Reputation: 39,103

» Sat Nov 22, 2014 6:57 pm

No joints at the moment, no.
B
34
S
10
G
5
Posts: 165
Reputation: 6,707

» Sat Nov 22, 2014 7:53 pm

Hi @Taurian Your formula looks ok.
Have you tried adding 360 if the result is negative? Would the angle look about right?
B
9
S
3
G
1
Posts: 346
Reputation: 1,560

» Sat Nov 22, 2014 7:55 pm

Negative angles are usually ok as well but, if you need to you can use this.
Code: Select all
(angle(0,0,Sprite.Physics.VelocityX,Sprite.physics.velocityY)+360)%360
B
34
S
9
G
3
Posts: 519
Reputation: 5,280

» Sat Nov 22, 2014 7:56 pm

Hi @Katala, yes that's kinda what I was getting at.
B
9
S
3
G
1
Posts: 346
Reputation: 1,560

» Sat Nov 22, 2014 8:39 pm

@Katala, thanks that did it!
Epic Space Online - Google it!
B
34
S
10
G
5
Posts: 165
Reputation: 6,707