Question by
nater1425 · May 25, 2016 at 08:15 AM ·
rotationmovementcharactercontrollercamera-movementwalking
im making a 1st person game and i dont know how to make the character walk where i want it to.im using character controller.
#pragma strict
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
var jumpHeight = 8;
private var isFalling = false;
function Update ()
{
//movement
if (Input.GetKeyDown(KeyCode.Space) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
isFalling = true;
}
isFalling = true;
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 ()
{
isFalling = false;
}
Comment
Your answer
Follow this Question
Related Questions
Keep position of CharacterController relative to rotating platform 0 Answers
having CharacterController movement in fixedupdate causes jerky movement on camera 3 Answers
how would you go about implementing terraria controls in unity? 0 Answers
i'm using a code to make my cube walk with character controller but when i play the cube spins. 0 Answers