I am attempting to create a side scrolling 2.5 plat former, but instead of straight platforms, I’m thinking about creating one continuous plat former, or one that loops. How do I keep the character grounded so it won’t fall off this circular platform?
Here’s the script I have on my character as of now.
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
moveDirection = Vector3(0,0,Input.GetAxis("Horizontal"));
moveDirection *= speed;
if (moveDirection.sqrMagnitude > 0.01)
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (moveDirection), 1);
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -=gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}