Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Movement Physics

Discussion in 'Physics' started by Skyhighjinks, Nov 8, 2019 at 4:56 PM.

  1. Skyhighjinks

    Skyhighjinks

    Joined:
    Nov 7, 2019
    Posts:
    3
    Heya all,

    So Im new to Unity and C#, so please dont bash me in too hard ! :D
    Im attempting to make a way for a player to "glide" through the air if they were to jump and move forward. THey cannot move while in mid air, but if they already issued a forward as they did the jump command, then they would move forward and jump. However, with the code below, they only jump when the conditions are met?

    I've tried the following:
    if(forward && sprint && jump){
    GetComponent<Rigidbody>().AddForce(Vector3.forward * sprintSpeedCalc);
    GetComponent<Rigidbody>().AddForce(Vector3.up * jumpPower * Time.deltaTime);
    Debug.Log("forward && sprint && jump");
    }


    if(forward && sprint && jump){
    GetComponent<Rigidbody>().AddForce((Vector3.forward * sprintSpeedCalc) + (Vector3.up * jumpPower * Time.deltaTime));
    Debug.Log("forward && sprint && jump");
    }


    The whole script: https://pastebin.com/J3tKKLzH
     
  2. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    40
    Not sure if I exactly understand, but you should condition the sliding when the player is in air e.g

    if(Player.OnGround()==false){
    GetComponent<Rigidbody>().AddForce(Vector3.forward * sprintSpeedCalc);
    }