- Home /
Character Controller Velocity Control
Hi Everyone.
Looking for a bit of help with controlling the velocity within the CharacterController.
The scene set up is simple. It's a basic platformer with the player running along the X axis. On the Y and Z there's a circular spline.
I'm currently aligning the players Y and Z orientation to a circular spline and applying, via the Character Motor, a local force downwards ie :
var gravityDirection = transform.TransformDirection (Vector3.down);
The goal is to have the player fixed to the circular spline and loop around when they fall. However, as expected, the velocity gets carried away and the player spirals out further from the center.
To get the player to "loop" around the circle I did the following in the ApplyGravityAndJumping function:
velocity.z = movement.velocity.z - (gravityDirection.z movement.gravity) Time.deltaTime;
velocity.y = movement.velocity.y - (gravityDirection.y movement.gravity) Time.deltaTime;
In other words, proportionally add the gravity to push the player around. This accomplishes the basic task of pushing the player in a full loop - but, irritatingly, the spirals get increasingly larger.
Can anyone suggest a way to monitor the velocity values and correct this spiralling effect? Perhaps increasing the movement.gravity proportionally? The goal is to have this working with any shape of spline and no need to fix the players transform.position to the spline
I'm at a loss, any help would be greatly appreciated