Physics Angle of Motion

Get help using Construct 2

Post » Tue Feb 25, 2014 12:57 pm

Does anyone know of a non-cpu intensive way of measuring a physics objects' angle of motion?

ATM I base the angle on an earlier position and compare it to a current one. However, to get this smooth it is calculating it every 0.01 seconds, and I think this may be pretty intensive.

Say for example I'm trying to 'animate' an arrow so that it launches into the sky and falls down, with the arrow head always leading the way. The thing is, I have to use physics.

Any ideas?
B
79
S
12
G
7
Posts: 961
Reputation: 10,717

Post » Tue Feb 25, 2014 3:23 pm

This should be ok

angle(sprite.X,sprite.Y,sprite.X+Sprite.Physics.VelocityX,sprite.Y+Sprite.Physics.VelocityY)
B
34
S
9
G
3
Posts: 517
Reputation: 5,206

Post » Tue Feb 25, 2014 4:44 pm

would

=atan(sprite.physics.velocityY / sprite.physics.velocityX)

work ?

(Not tested )

Edit:

Close - but no.

https://www.dropbox.com/s/b749rcrcc7si976/atan%20drag%20test.capx
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Tue Feb 25, 2014 7:01 pm

@Katala

Thank you! This should help me greatly! I have a feeling the other way I was doing it was quite intensive.
B
79
S
12
G
7
Posts: 961
Reputation: 10,717

Post » Tue Feb 25, 2014 7:41 pm

@Katala @AnD4D

you can lose the sprite coordinates and just have:

angle(0,0,Sprite.Physics.VelocityX,Sprite.Physics.VelocityY)
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Tue Feb 25, 2014 10:25 pm

@keepee So you can! Is it worth re-exporting my project for this change? Will it make even the slightest improvement to performance?

If the answer is yes, then I will go ahead and do that.
B
79
S
12
G
7
Posts: 961
Reputation: 10,717

Post » Thu Feb 27, 2014 3:38 pm

@AnD4D

unless you're doing it 100,000 times a tick, it will make no difference.
It's just for simpler readability
B
28
S
8
G
1
Posts: 469
Reputation: 4,683


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests