Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can't use AddRelativeForce properly

Discussion in 'Scripting' started by cube_sniper24, Apr 20, 2021.

  1. cube_sniper24

    cube_sniper24

    Joined:
    Aug 7, 2020
    Posts:
    13
    I am trying to use rigidbody's AddReletive force to make the movement in my game less stale as it is with just using transforn.Translate, but when I try to use it, it launches my character up as well as forwards.

    Code (CSharp):
    1. private void FixedUpdate()
    2.     {
    3.         if (Input.GetKey(KeyCode.W))
    4.         {
    5.             if (IsRagDoll == false)
    6.             {
    7.                 body.GetComponent<Rigidbody>().AddRelativeForce(0, 0, -8, ForceMode.Impulse);
    8.             }
    9.         }
    the game object "body" is linked to my character that I am trying to move.
    if you need to see more, let me know, and I can send it.
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Relative means it takes the transform's rotation into account.
     
  3. cube_sniper24

    cube_sniper24

    Joined:
    Aug 7, 2020
    Posts:
    13
    yes, I need that so when the character turns around it will still move forwards, but it's rotation is 0, 0, 0 so I don't know why it is going up.

    edit: it never rotates on the x axis, only the y