- Home /
Checking which thruster to fire. Need help with the math
I'm trying to figure out which thruster to fire in a top-down 2D game. As far as I understand, I'm supposed to get the dot product between the torque of the thruster, and the direction I'd like to move the ship. I've tried looking up articles trying to do the same thing, but I ended up more confused than anything. I've currently got the following code.
public void AngularBurn(Vector3 localAxis, float throttle)
{
if (Thrusters.Count > 0)
{
foreach (Thruster thruster in Thrusters)
{
if (thruster == null)
{
Thrusters.Remove(thruster);
GetAllThrusters();
break;
}
float Power = 100;
Vector3 Displacement = CenterOfMass.transform.position - thruster.transform.position;
Vector3 Force = thruster.transform.up * Power;
Vector3 Torque = Vector3.Cross(Displacement, Force);
Debug.Log(Vector3.Dot(Torque.normalized, localAxis));
}
}
}
Where localAxis is transform.right of the ship, since I want the ship to rotate clockwise. This gives me the following results
The arrows are thrusters pointing in the same direction as the exhaust would be. What I would expect to see is the two first logs showing positive values, and the next two showing negative ones. What am I doing wrong here?
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How to detect if number has a decimal point or not 2 Answers
Minimap rotating nodes 1 Answer
Make 3D Player look exactly at mouse with ScreenToWorldPoint? (maths Question) 2 Answers