Applying thrust and torque in relation to center of mass
I have been working through this tutorial here, however being relatively new to programming, I'm having a bit of trouble with some areas of it. I believe, or at least hope I'm in the right ballpark with my calculations, I'm just not sure how to apply them!
I have a parent ridgidbody and two child thruster rigidbodies with the following script applied to each.
X = transform.position.x;
Y = transform.position.y;
pos = new Vector2(X, Y);
// Should I be using these anywhere?
float angle = Mathf.Deg2Rad * Vector2.Angle(direction, forward);
Vector2 direction = COM - pos;
Vector2 forward = transform.up * force;
Vector2 distToCOM = pos - COM;
float torque = distToCOM.magnitude * forward;
if (Input.GetAxis("Vertical") > 0)
{
parentRB.AddForceAtPosition(torque,pos);
}
if (Input.GetAxis("Vertical") < 0)
{
// Not done yet
}
I'm not entirely sure how to correctly get the force vector either. Though with what I've got here I don't think I'm too far off, I'm just getting some unexpected movement.
If anyone could point me in the right direction as to where to go from here, it would be much appreciated!
Here's a link to Captain Forever, the player movement of which I'm trying to emulate. Thanks!
EDIT: I've made a few changes and I think I've managed to get it a bit closer with the above, but still getting some wonky movement.
Your answer
Follow this Question
Related Questions
Movement input problem? 1 Answer
Character Movement on Cylinder Surface 0 Answers
Isometric movement for MoveTowards 0 Answers
Stop movement on collision 1 Answer