- Home /
character controller
My character moves on the x and y axis but im trying to make move in the z axis too so he can turn around... This What I have:
using UnityEngine; using System.Collections;
public class MovementCharacter : MonoBehaviour { public float speed = 6.0F; public float jumpSpeed = 8.0F; public float gravity = 20.0F; private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new 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);
}
}
Answer by diabloroxx · Oct 14, 2010 at 06:51 PM
Did you have a look at the First Person Shooter tutorial? http://unity3d.com/support/resources/tutorials/fpstutorial
It pretty much has the user moving everywhere.
Well im trying do a third person game not a FPS and the tutorial doesn't show you any code about the character controller
In that case, check out the Boot Camp demo which was released with Unity3. The character controller is a part of the prefab object which you attach.
Your answer
Follow this Question
Related Questions
Difference between a rigidbody and a character controller? 1 Answer
Character controller and MouseOrbit Camera(don't work togheter) 2 Answers
Making a Model move with the Mouse 1 Answer
Player moves diagonally even when not telling him to 0 Answers
How can i add a collision detection for a character controller? 1 Answer