What is difference between these two lines of codes?
rb.velocity = new Vector3 (rb.velocity.x, 5f,rb.velocity.z);
rb.velocity = new Vector3 (0, 5f,0);
both codes are in the this logic (if (Input.GetButtonDown("Jump"))
In the first case you specify that velocity of your rigidbody should retain x and z value, and set y component of velocity to 5.
In the second example, you set velocity to the numbers you given.
If before setting value x and z values of rb.velocity were 0, both statements will do the same.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.