Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

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));

    }
    }