Question by
nater1425 · May 31, 2016 at 01:03 AM ·
rotationmovementrigidbodytransformcharactercontroller
i'm using a code to make my cube walk with character controller but when i play the cube spins.
#pragma strict
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(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function OnCollisionStay ()
{
}
Comment
Your answer
Follow this Question
Related Questions
i am using a code to make my cube walk with character controller ,but when i play the cube spins. 0 Answers
try to rotate a character controller when translating on z only 0 Answers
Character bounces off walls, and drops to the ground on movement 1 Answer
Character Controller Move function Explanation 0 Answers
Why does the player not move around planet with gravity ? 1 Answer