Detection of sprite rotation

For questions about using Classic.

Post » Tue Jun 14, 2011 9:43 am

(Yup, me again)
So, sprite X is rotating. It can rotate clock and counter-clockwise. I am trying to figure out how can the engine detect that rotation and perhaps also detect in which side its rotating.

On example:
Lets say a spaceship is flying. now he rotates. When he rotates i want him to "lean" in left or right side. This is achieved by changing the animation for a moment.

The problem is - i am trying very hard and i cant find a method to trace the rotation or its direction. Same for tracing if the angle is increasing or decreasing or even if its changing in general.

I though that i could perhaps use PV and set it to angle. Then with events monitor if the PV is going up or down and attach this as a condition for the animation change but theres also no "increasing"/"Deacresing" condition for PV neither.

I am playing in my mind with an idea to create a "phantom" sprite attached on top of the original, with rotation behaviour but with faster rotation speed.
So lets say the Main Sprite angle is 180 and Phantom Sprite angle is 180. Now the Phantom sprite is turning right so his angle increases. In first secund the angle of Phantom is now, lets say, 250. When Main angle is still around 180. Both are turning but the angle of Phantom is higher then the angle of Main.

This is when i can make it a triger. So:
If system value compare Main.Angle lower then Phantom.Angle then -> change animation to "lean right"
If system value compare Main.Angle greater then Phantom.Angle then -> change animation to "lean left"

But i havent tested this yet. Its just an idea. Maybe not that complex but also far from elegent and simple (if it works that is).
Also this preety much doubles each and every moveable-rotatating sprites in the game. needlessly. So if theres a huge battle going on and theres 50 enemies. Each made out of 3 linkes to each other animated sprites + 50 extra Phantom sprites... well, you got the idea. messy.
Posts: 211
Reputation: 3,787

Post » Tue Jun 14, 2011 10:09 am

curAngle = current angle
oldAngle = old angle
dAngle = angle difference

dAngle = oldAngle-curAngle

Basically store the angle in oldAngle to use for next calculation. You can also checks every 100ms or so (not every frame), compare the angle 100ms ago and now, then you can find out where it is leaning from the difference. You can also apply different levels of tolerance; negligible angle difference shouldn't change the angle, value between 1 and 15 would result in slight leaning, value above 15 into more powerful leaning etc.
Posts: 1,910
Reputation: 13,685

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests