Search Unity

Add force to player at a certain z rotation in 2D

Discussion in '2D' started by AryanJumani, Jun 3, 2020.

  1. AryanJumani

    AryanJumani

    Joined:
    Sep 6, 2018
    Posts:
    14
    Hello, I want to add a force at a certain z angle(which is a moving arrow going in a circle). I have accessed the rotation of that arrow by using
    Code (CSharp):
    1. arrow.transform.rotation.eulerAngles.z
    So now how do I add a force on the player at the above z rotation? Thanks a lot in advance!! ^_^

    Note: This whole project is in 2D
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    If you're applying a force, you must have a Rigidbody2D so use its API and NOT the Transform. The Transform is for rendering etc. Use Rigidbody2D.rotation. It's worth browsing the API docs for the Rigidbody2D. There you'd find Rigidbody2D.AddRelativeForce which allows you to add a force in the bodies local space. Up is the local up of the body; no need to refer to its rotation.
     
    AryanJumani likes this.