Hey all,
I’ve been banging my head for a while trying to get a working system that converts player input into thruster throttle setting. The trick is the user places them at runtime so I can’t know head if a thruster is used for pitch/roll/yaw.
So here are just a few things I’ve tried. Many of them work for some rotations, but not others. I can’t find a single method that works for all possible rotations of both the thruster and input.
All thrusters can be used from -1 (100% reverse) to 1 (100% forward). And since it’s a rotational force, a thruster’s forward vector can match or be rotated 90 degrees and still apply some rotation force correctly.
Thanks for any help! I’ve been going nuts trying to figure this out and just can’t wrap my head around it.
Vector3 inputDir = transform.TransformDirection(Input.GetAxis("horz"), Input.GetAxis("Vert"), Input.GetAxis("Roll"));
for (int i = 0; i < thrusterArray.Length; i++)
{
//snip, different methods I've tried
// method 1
float throttle = Vector3.Dot(thrusterArray[i].transform.forward, inputDir);
// method 2
Vector3 projected = Vector3.Project(inputDir, thrusterArray[i].transform.forward);
float throttle = Vector3.Dot(thrusterArray[i].transform.forward, projected);
// method 3
Vector3 rotatedInput = thrusterArray[i].transform.rotation * inputDir;
float throttle = Vector3.Dot(thrusterArray[i].transform.forward, rotatedInput);
// method 4
Vector3 thrusterCoMDir = Vector3.Normalize(transform.InverseTransformPoint(thrusterArray[i].transform.position)
- _rigidbody.centerOfMass);
Vector3 projected = Vector3.Project(thrusterCoMDir, thrusterArray[i].transform.forward);
float throttle = Vector3.Dot(projected, inputDir);
// finally apply the forces
_rigidbody.AddForceAtPosition(thrusterArray[i].transform.forward * Throttle * scaleForce, thrusterArray[i].transform.position);
}