Question by
nater1425 · May 30, 2016 at 10:03 AM ·
rotationmovementrigidbodytransformcharactercontroller
i am 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);
}
Comment
I'm not sure, so I'm asking. You said you want the cube to walk with the character controller, and I was just wondering if you have attached the character to another game object, because sometimes it happens for me, so ins$$anonymous$$d I use fixedjoint. But I'm not sure if this is the case for you
Your answer
Follow this Question
Related Questions
i'm using a code to make my cube walk with character controller but when i play the cube spins. 0 Answers
Control speed of a rigidbody that move to a fixed distance 2 Answers
Converting my Character Controller Movement to Rigidbody 1 Answer
DESPERATE How to align transform.up with another vector3 (direction) ? 1 Answer
Player rotates spastically on all axes when camera is turned 0 Answers