Search Unity

Apply 2D force

Discussion in 'Editor & General Support' started by indy2005, Mar 13, 2014.

  1. indy2005

    indy2005

    Joined:
    Aug 22, 2009
    Posts:
    81
    Hi,

    How do I apply a force to a 2D rigid body in the up direction of the rigid body. i.e. to make a rocket thrust, the thrust needs to be applied in the tail to nose direction (up in local space).

    Do I use Vector2.up, use Fixed update, use delta time?

    Any help appreciated.

    Regards

    i
     
  2. indy2005

    indy2005

    Joined:
    Aug 22, 2009
    Posts:
    81
    This seems to do it, do I not need delta time (and if so how), if I use fixedUpdate?

    void FixedUpdate() {
    if(isThrusting) {
    Rigidbody2D shipBody = ship.GetComponent<Rigidbody2D>();

    shipBody.AddForce(new Vector2(ship.transform.up.x * thrustForce, ship.transform.up.y * thrustForce));

    }
    }