This page tries to describe how HoverEX deals with the physics of simulating the motions of the objects in the game.
An important thing to note is that the calculation step for HoverEX is dynamic. It depends on the FPS and collision prediction of the game.
HoverEX engine base it’s simulation on momentum rather than acceleration. This is due to the fact that it is more consistent with the way collision reaction works (using momentum) and also for torque simulation in the future.
HoverEX does not implement Torque. Torque is the reaction of an object spinning resulting from a collision with friction.
This however might change in the future when I get my hands on understanding how to implement it. For now, I’m keeping things as simple as possible just so I don’t get all fused up with this physics thing.
On second thought, this torque thing might end up distrupting game play. (hovercraft spinning uncontrollably every time they collide)
Another unrealistic part of the physics engine is the collision reaction system where every collision are perfectly elastic. That means no energy is lost during collisions. This is mainly because I don’t know how to calculate it. Hope some physics guy would beable to help me here.
— Pang Lih-Hern 2005 08 08, 02:05
Forward Motion is pretty straight forward.
pos.x += vel.x * dt pos.y += vel.y * dt
As indicated from the Basic Physics page, thrust is always the reverse force of the exerting direction.
F = -ma
with that, hence given the thrust an object can exert, we can find the accelerated thrust produced on the object.
a = - (F / m)
But since we don’t really care about thrust but more about the impulse exerted to the object, we just simply use the Impulse formular.
I = F * dt
Changing it to the coordinate system,
Let Fm = Thrust Magnitude,
θ = Thrust direction (hovercraft's direction; NOT moving direction)
Ix = Fm * cos θ * dt
Iy = Fm * sin θ * dt
Or, using the unit vector of the hovercraft’s direction,
Let dir = unit vector of craft's direction Ix = Fm * dir.x * dt Iy = Fm * dir.y * dt
HoverEX simulates two main type of reseistance. Drag and Friction.
Drag happens when a object moves through a liquid or gas. It is a force that goes against the moving direction of the object. Without drag, objects can keep on accelerating at a constant rate given if fuel is infinite. Since we don’t want that, drag is nessesary to limit the object’s top speed.
Let c = coefficient of drag (typically between 0.30 and 0.35)
A = object's cross-sectional area
p = air density
v = object's velocity
dV / dt = - (c * A * p * v ^ 2) / 2
Looking at above, we can see that it is quite impossible to calculate drag as we do not have enough information on our object. Two main thing that we lacked of is the Coefficient of drag and the object’s cross-sectional area.
Being that, a reasonable number have to be given using test cases.
From the above we can also see that the formular is depending on the velocity of the object. This means that the faster the object move, the more Drag it is going to feel. And it will not feel any Drag at all if it is not moving.
Without friction, ignoring drag, an object can move infinitely along a straight line without exterior inteference. However, this is very unrealistic as even hovercrafts do still rub against the ground surface. Hence, there will still be a small tiny bit of friction.
Friction as a force is pretty much useless to HoverEX physics simulation. What is needed is the resistance due to friction.
let Ff = magnitude of the friction force Ff = Fp * u Ff = m * g * u
Turning it scalar in conjunction to X and Y axis,
let V = unit vector of moving velocity Ffx = V.x * m * g * u Ffy = V.y * m * g * u
Since this is supposed to be a decceleration, we negate the value.
Ffx = - V.x * m * g * u Ffy = - V.y * m * g * u
Hence from the above, we can sum up the resultant resistance decceleration of an object.
Let Fr = Resistance force (magnitude)
Ff = Friction force (magnitude)
Fd = Drag force (magnitude)
C = c * A * p / 2 (constant value for drag calculation)
Fr = Ff + Fd
= - (m * g * u) - C * (V ^ 2)
A special case follows where if the impulse of the resistance is greater than the momentum of the object, the object comes to a full stand still.