Description
The Velocity
property of the CharacterController
class represents the current velocity of the character in the game world. It is a Vector3
type, which means it contains three components: X, Y, and Z, corresponding to the three-dimensional space in which the character moves.
This property is synchronized across the network, as indicated by the SyncAttribute
, ensuring that all clients have a consistent view of the character's velocity.
Usage
Use the Velocity
property to get or set the current velocity of the character. This can be useful for implementing custom movement logic or for responding to changes in the character's speed.
When setting the velocity, ensure that the value is appropriate for the character's movement capabilities and the game's physics rules. The velocity should be updated in response to player input or game events, such as collisions or environmental effects.
Example
// Example of setting the Velocity property
CharacterController characterController = new CharacterController();
// Set the character's velocity to move forward at a speed of 5 units per second
characterController.Velocity = new Vector3(0, 0, 5);
// Example of getting the Velocity property
Vector3 currentVelocity = characterController.Velocity;
// Output the current velocity
// Note: Avoid using Console.WriteLine in Sandbox environment
// Instead, use in-game UI or debugging tools to display the velocity
// Debug.Log(currentVelocity);