I’m currently working on a 2D space shooter game. I’ve decided to model everything using pure Newtonian mechanics. Is there a way to simulate rotation using two force thrusters?
What I do at the moment is I create a parent GameObject and put two thruster objects into it some distance apart of each other. I then apply force to those thrusters in hopes of moving the parent object, sadly nothing happens. What am I doing wrong?
You can use Rigidbody2D.AddForceAtPosition. You can use a simple script as follows:
public Transform leftThruster;
public Transform rightThruster;
public float force;
Vector2 forward = new Vector2(transform.up.x, transform.up.y);
Vector2 leftThrusterPos = new Vector2(leftThruster.position.x, leftThruster.position.y);
rigidbody2d.AddForceAtPosition(force * forward, leftThrusterPos);
//Same for rightThruster
You can modify the code to add force only to one thruster to turn, i.e. when the left key is pressed, the right thruster will only provide the thrust and vice versa.