# Smooth rotational animation..

This topic is 4379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I need some help with a game i'm working.. I have a ship situated at the centre of the world with meteors which I spawn from multiple positions (along a perimeter from the world origin) in space and travel towards the ship to try to destroy it.. Each meteor has a bounding sphere of radius (rMet) and the ship has a bounding sphere of radius (rShip).. On collision i'm trying to create an impact animation where the ship rotates slightly depending on where the meteor hits and then slowly moves back into its default rotation.. I'm having a world of trouble with the math and was hoping to get some advice on how best to handle it..? Thanks Gamedev!

##### Share on other sites
If the spaceship only rotates and does not shift, the rotation should be proportional to the tangential component of the velocity of the meteor.

Let the black circle be the ship, the blue arrow (B) be the velocity vector of the meteor, and the red line (R) be the vector from the point of impact to the origin. Then the rotation is proportional to the the magnitude of the green line (G).

Let r and b be the normalized vectors of R and B.

The angle theta = arccos( r dotproduct b )

The magnitude of G = sin(theta) * magnitude of B.

Suppose the ship rotates back to its default rotation automatically, I would model the disturbance as an offset that dampens over time.

You can dampen the offset by a factor every time interval instead of decrementing it by a fixed amount to give it a more organic feel.

##### Share on other sites
So what is G?

I understand that this is the proportion of the rotation with respect to the angle and velocity of the meteor.. But is G an angle itself? if not how would i convert it into an angle from the verticle..?

also how would I do the dampening for the smooth rollback..?

I've played around with it before but my math was poor and it didn't work at all..

##### Share on other sites
G is the green line. It is the component of B that is tagent to the circle.

Let B be the velocity vector of the meteor (e.g. B = <-2.5,-0.5>).
Suppose the rShip is 1, and the meteor collides at (1,0).
Then the vector R = <-1,0>.
Theta = arccos( B dot R ) / ( mag(B)*mag(R) )
mag(G) = 0.5

The rotation is proportional to mag(G). Suppose the proportion constant is 10. So the ship is going to rotate by 0.5 * 10 = 5 degrees per unit time.

Suppose the orientation of the ship is:

oShip = oShip + voShip + impactvo

where oShip is the angular position and voShip is the angular velocity, and impactvo is the offset we calculated. Then in a given time frame, you can dampen impactvo by:

impactvo *= dampingratio

where dampingratio is a number less than 1. To make this particular method work, your ship needs to track its target orientation. Let toShip be the target orientation, then

voShip = (toShip - oShip)/trackingdelay

where trackingdelay is greater than 1.

##### Share on other sites
Thanx alot! I think that should work great!

I'll give it a try!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 10
• 9
• 36
• 16
• ### Forum Statistics

• Total Topics
634125
• Total Posts
3015681
×