Search Unity

How To Increase Velocity On A Specifically Defined Direction

Discussion in 'Physics' started by FringeFinch, Sep 24, 2018.

  1. FringeFinch

    FringeFinch

    Joined:
    Aug 22, 2018
    Posts:
    1
    Hey, currently I'm trying to set a velocity in a specific direction that I defined. The direction I'm using is based on the trigonometry concept of a unit circle. This is how I calculated the direction I want to define.

    Code (CSharp):
    1.  
    2.         XRight = Mathf.Cos(GroundAngle);
    3.         YRight = Mathf.Sin(GroundAngle);
    4.  
    5.         XLeft = XRight * -1;
    6.         YLeft = YRight * -1;
    7.  
    8.         RightDir = new Vector2(XRight, YRight);
    9.         LeftDir = new Vector2(XLeft, YLeft);
    GroundAngle is the angle that the player character is currently tilted on. Using this angle I made two vector2 that are supposed to act as the "new" left and right directions relative to the player's angle. Using these new direction definitions, how do I go about adding a velocity only to the defined direction? I've tried a few solutions including using "AddForce" on the rigidbody, but it doesn't produce the results I'm looking for. "AddForce" seems to behave differently than "velocity".