I’m trying to make a create-your-own-plane and flight simulator game that will allow users to place engines at various positions around the plane.
Because of this I want to use Rigidbody.AddForceAtPosition to apply the thrust produced by each engine wherever it may be and at whatever orientation. I have set up a simple test with my plane with one propeller at the nose but I’m having an issue with it - the plane is pulled forward as expected but as soon as I try and pull up, the force from the engine is immediately slamming the nose back into the ground.
The associated code is here (thrust is just a float I have hard-coded at this stage):
private void UpdateThrust()
{
foreach (var engine in engines)
{
var thrust = engine.CalculateThrust(inputManager.Throttle,
RigidBody.velocity.magnitude);
var direction = engine.transform.forward;
var position = engine.transform.position;
RigidBody.AddForceAtPosition(thrust * direction, position);
}
}
Have I made a mistake, or is this a side effect of using this method and can anyone suggest a solution?