Vector3 Velocity { get; set; }

robot_2Generated
code_blocksInput

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 debugging purposes to understand how the character is moving at any given time.

When setting the velocity, ensure that the value is appropriate for the game's physics and movement mechanics. The velocity should be updated in response to player input or game events, such as applying acceleration or friction.

Example

// Example of accessing and modifying the Velocity property

// Assuming 'controller' is an instance of CharacterController
Vector3 currentVelocity = controller.Velocity;

// Print the current velocity
// Debug.Log(currentVelocity);

// Set a new velocity
controller.Velocity = new Vector3(5.0f, 0.0f, 0.0f); // Move the character along the X-axis

// Apply acceleration to the current velocity
controller.Accelerate(new Vector3(1.0f, 0.0f, 0.0f));

// Apply friction to slow down the character
controller.ApplyFriction(0.5f, 0.1f);