6
\$\begingroup\$

When a arrow shaped object is fired it slowly adjusts it's rotation to match the direction it is moving. But what is the actual physics behind it?

enter image description here

The question is: How many degrees does the ship turn in a second?

I usually approximate the effect by simply setting the rotation to the angle of the velocity, however this is not possible this time since the player is able to influence the rotation of the ship by steering.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ gravity does not affect rotation at all because it applies to the center of mass. air drag however does! the easiest way to simulate it is to calculate and apply the correct amount of drag at "draggy" parts (tail fins, etc.) of your object. \$\endgroup\$ Feb 10 '14 at 3:48
4
+50
\$\begingroup\$

1: Simple physics

There will be a subtle difference in drag on either side*, because the side rotating into the wind will have greater dynamic pressure than the one that rotates with the wind. For an arbitrary shape, this will be somewhat difficult to calculate (although possible) for correct physics. You should not try, and approximate it instead. This approximation can simply be proportional to flow velocity. This is sort of physically accurate, and very simple to calculate.

For a ship, which presumably has roughly the same shape as an arrow with something "draggy" at the downstream end of it, this effect will be proportional to the ship's alignment with the direction. For example, (1 - direction.dot(rotation)) might work well. This will also be affected by the magnitude of rotational speed.

So for an overall system, rotational acceleration due to drag will be roughly:

velocity.length * rotationSpeed * (1 - direction.dot(rotation)) * 
    SOME_UNSCIENTIFIC_CONSTANTS * getDragRotationDirection();

This will likely result in an oscillating rotation. It will bounce around its own aligned direction. You will need to tweak the code to dampen that somehow.

2: for 2D physics-based system:

Treat the tail-fins (or whatever) as the location to apply a constant impulse proportional to velocity in the direction opposite velocity. Because this location should be offset from the center of mass, it will yield a moment that will rotate the ship back toward the forward-direction. When the ship is aligned with that direction, it will yield no rotation.

For this method, be wary of the special case where the tail is pointed almost directly into the wind. That might yield weird results.


*Side: The cross product of the flow direction (opposite direction of movement) and the axis of rotation (for 2D, unit-z), will yield a "side". The other side is the opposite direction.

\$\endgroup\$
6
  • \$\begingroup\$ Wait, wouldn't direction.length and rotation.length always be 1? \$\endgroup\$
    – API-Beast
    Feb 10 '14 at 17:20
  • \$\begingroup\$ I tried to implement this, it seems to work however I have the problem that it happens frequently that it goes into a kind of overdrive where it just keeps increasing the speed of rotation, e.g. spins to death. My code looks like this: gist.github.com/API-Beast/634e78f5d408f3387b83 \$\endgroup\$
    – API-Beast
    Feb 10 '14 at 17:41
  • \$\begingroup\$ In that gist, what is the net value for (AirDrag * obj->Drag * dt * 20) * obj->RotationSpeed? Possibly clamp it to be no less than zero, to make sure that never accelerates the rotation. \$\endgroup\$ Feb 10 '14 at 18:28
  • \$\begingroup\$ About your other comment, you are right, I used bad variable names there. What I meant to write was: the magnitude of velocity and the speed of rotation. I also noticed that the term (1 - direction.dot(rotation)) will need to be positive or negative. One way to determine it would be direction.cross(rotation), where the Z-axis result sign indicates direction. \$\endgroup\$ Feb 10 '14 at 18:30
  • 1
    \$\begingroup\$ Found the error, the rotation itself needs to changed, not the rotation speed. Code looks like this now: gist.github.com/API-Beast/634e78f5d408f3387b83 \$\endgroup\$
    – API-Beast
    Feb 11 '14 at 11:37
1
\$\begingroup\$

When a arrow shaped object is fired it slowly adjusts it's rotation to match the direction it is moving. But what is the actual physics behind it?

The Physics behind it is a combination of G-Force(gravity acceleration) and Aerodinamics. An arrow usually has a head, a body segment and a tail, the mass center will be near to the head. Although G-Force pulls the whole arrow towards the ground, the shape differences between the head and the tail create different Aerodynaics reactions.

The tail of the arrow offers more air resistance along the G-force direction than the head, thus the head will fall to the ground faster. As head and tail are connected through the body segment, the tail will act as a pivot creating rotation. The rotational speed (degrees) will depend on the shape of the arrow.

In your case the rotational speed will depend on the ship shape. If I were you I would separate the ship into segment and give each segment different gravity acceleration penalty, this penalty will simulate air resistance and the segment with most resistance will act as the pivote point.

Calculate the mass center of each ship segment and calculate the following cross product for each ship segment:

Ti =(distance to pivot)cross(PivotPenalty-SegmentPenalty)*m

Penalty must be un the opposite direction of G Force.Whit m being the masas of the segment

Sum all Ti to get the final total Torque, now you can associate this value to a rotational speed value.

\$\endgroup\$
-1
\$\begingroup\$

To answer: How many degrees does the ship turn each frame? u need to know how many frames per second u will have. But let's say u have 60 frames per second.

Knowing how many degrees the ship turns per second is just a matter of math. I would solve this using vectors:

  • Calculate the new vector every 1/60th of a second
  • Save the current position of the object(will become the old position after move)
  • Move the object using that new vector every 1/60th of a second
  • Use trigonometry to calculate the angle between the old and new position ( use center circle as third vertex)

Remember:

  • Gravitational acceleration's unit is m/s^2
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.