Description
The Velocity
property of the Rigidbody
class represents the linear velocity of the rigidbody in world space. It is a Vector3
value that indicates the speed and direction at which the rigidbody is moving.
This property is synchronized across the network with a priority level of 2, ensuring that changes to the velocity are propagated to all clients in a multiplayer environment.
Usage
To access or modify the velocity of a Rigidbody
, you can use the Velocity
property. This can be useful for directly setting the speed of an object or for reading its current speed to apply further calculations or logic.
Note that directly setting the velocity can override any forces or impulses applied to the rigidbody, so it should be used with consideration of the overall physics simulation.
Example
// Example of setting the velocity of a Rigidbody
Rigidbody myRigidbody = new Rigidbody();
myRigidbody.Velocity = new Vector3(10, 0, 0); // Sets the velocity to 10 units per second along the x-axis
// Example of reading the velocity of a Rigidbody
Vector3 currentVelocity = myRigidbody.Velocity;
// Use currentVelocity for further calculations or logic