Hey guys,
so I'm building a 3D (what I guess is 2.5D really) platformer but having a bit of trouble with the character control.
I am using basic shapes at the moment, so a capsule with a character controller on it, and some cubes for the level. I can move left and right, and jump just fine so the actual movement is not at all an issue. What I am unable to figure out (and may not be possible) is rotating the capsule (to be replaced with a model later) to look in the direction he's going. I tried googling, other answers on here, and youtube and can't seem to find one specific to my issue.
Here is what I have so far.
public class PlayerController : MonoBehaviour {
[Range(1.0f, 10.0f)]
public float movementSpeed = 1.0f;
[Range(1.0f, 15.0f)]
public float jumpSpeed = 8.0f;
[Range(1.0f, 30.0f)]
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
private CharacterController controller;
// Use this for initialization
void Start () {
controller = GetComponent();
}
// Update is called once per frame
void Update () {
// if we are on the ground
if(controller.isGrounded)
{
// we are on the ground so calculate the direction
moveDirection = new Vector3(Input.GetAxis("Horizontal") * movementSpeed, 0, 0);
moveDirection = transform.TransformDirection(moveDirection);
// jump
if(Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
// apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// move
controller.Move (moveDirection * Time.deltaTime);
// kill us at the bottom...
if(transform.position.y
Trending Articles
More Pages to Explore .....