Oh man, I am so excited. After much studying this noob has invented flight!
I’ve got my falcon model up and moving and mostly under control. The problem is that a change in direction (rotation) does not affect my thrust force. Basically what happens is I can roll and nose up or down to make turns, but if I turn too sharp or yaw too much the falcon model is flying bass ackwards.
I messed around with the angular drag a bit, but that didn’t seem like the right fix. How is it that I can keep my forward velocity tied to my current rotation?
I really appreciate any help. This is my first effort at creating my own code and it’s really exciting to be producing wanted results-- help me keep up my momentum!
Here is my code:`public class FlightControl : MonoBehaviour {
//Birds mass and drag
Rigidbody rigidBody;
//Pitch, yaw, and roll control factors
public float rollSpeed;
public float pitchSpeed;
public float yawSpeed;
//how strong the wings flap, how much force they apply forwards and upwards
public float thrustPower;
public float upThrust;
public float forwardThrust;
//Lift and drag, will be defined in seperate functions; dragFactor defines the increasing scale that multiplies with velocity
//private float dragFactor;
private Vector3 liftFactor;
// velocity, will be defined in seperate function
private Vector3 forwardVelocity;
void Start()
{
SetInitialReferences();
}
void FixedUpdate ()
{
LiftOff ();
DirectionalControl ();
}
void SetInitialReferences()
{
rigidBody = GetComponent<Rigidbody> ();
birdBody = transform.position;
}
void DirectionalControl()
{
float h = Input.GetAxis ("Horizontal") * rollSpeed * Time.deltaTime;
float v = Input.GetAxis ("Vertical") * pitchSpeed * Time.deltaTime;
float y = Input.GetAxis ("Yaw") * yawSpeed * Time.deltaTime;
rigidBody.AddTorque (transform.forward * -h);
rigidBody.AddTorque (transform.right * v);
rigidBody.AddTorque (transform.up * y);
}
void LiftOff()
{
if (Input.GetButtonDown ("Jump"))
rigidBody.AddRelativeForce (0, upThrust, forwardThrust, ForceMode.Impulse);
}
}
`