Home > Blockchain >  Unity 3d C# player movement difference
Unity 3d C# player movement difference

Time:08-29

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"))

CodePudding user response:

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.

  • Related