How do I set an sprites angle to the angle of motion

Get help using Construct 2

Post » Thu Jan 08, 2015 12:55 am

Hi everyone,

i have a simple problem which i cant figure out my self.

i have a sprite which is moving and several other objects are applying a force to it:
force.PNG


so far it works very well, but the objects stays at the same angle, how do i get the object to rotate to the current angle of movement to make it look better?

the object has family bullets has the solid and the physics behavior. ive tryed to add the custom movement behavior and set angle to self.CustomMovement.MovingAngle but it doesnt change anything :(

any suggestions?
regards patrick
You do not have the required permissions to view the files attached to this post.
B
19
S
7
G
1
Posts: 222
Reputation: 2,546

Post » Thu Jan 08, 2015 1:12 am

If the object you want to rotate uses car motion, the behaviour has the expression VectorX and VectorY, which give the movement of the object in each of these axis i.e. it splits the current movement into its perpendicular components. The angle of movement can then be calculated. Taking 0 degrees as the positive x axis, the direction of movement equals:

if x > 0 & y > 0 :
a = arctan(VecX/VecY)

if x < 0 & y > 0 :
a = 180 + arctan(VecX/VecY)

if x < 0 & y < 0 :
a = 180 + arctan(VecX/VecY)

if x > 0 & y < 0 :
a = 360 + arctan(VecX/VecY)

There may not be VectorX and VectorY values for other behavious. You could calculate them basically by storing the last position of the object and comparing it with the new version and finding the difference in x and y. This method may make the rotation rough so you may have to use some interpolation methods to make it smoother.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Thu Jan 08, 2015 2:39 am

hi, thank you very much vor your answer, no it doenst use that movement, its just applying forces :(
well maybe i can figure out another way or rotate the angle to the greatest force..
B
19
S
7
G
1
Posts: 222
Reputation: 2,546

Post » Thu Jan 08, 2015 12:41 pm

okey, with the help of briggybrosive found a solution, looks pretty nice now :)

for those who are interested here it is: i gave my bullet family some instance variables, fill them first time when the oject is spawned and then update them constandly:
ad062a29fa662929af6d9a12ac3bb4f7.png


regards
Patrick
You do not have the required permissions to view the files attached to this post.
B
19
S
7
G
1
Posts: 222
Reputation: 2,546

Post » Thu Jan 08, 2015 6:42 pm

Glad I could help :)
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446


Return to How do I....?

Who is online

Users browsing this forum: guannstar and 18 guests