Hello, I am creating a 3D third person platformer and I have a third person camera that rotates around the player with the mouse.
I have been trying for days to try and get this to work properly but I have not came anywhere close.
What I am trying to achive is for the player to walk in the direction that the camera is looking at. I am out of options and I am resorting to asking here.
Thank you in advance for any help, it is much appreciated.
public class MoveTest : MonoBehaviour {
public float walkSpeed = 10.0f;
private CharacterController controller;
private float verticalVelcoity;
private float gravity = 30.0f;
private float jumpForce = 20.0f;
// Use this for initialization
void Start ()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update ()
{
//Jumping
if (controller.isGrounded)
{
verticalVelcoity = -gravity * Time.deltaTime;
if (Input.GetButton("Jump"))
{
verticalVelcoity = jumpForce;
}
}
else
{
verticalVelcoity -= gravity * Time.deltaTime;
}
//Movement
Vector3 moveVector = Vector3.zero;
moveVector.x = Input.GetAxis("Horizontal") * walkSpeed;
moveVector.y = verticalVelcoity;
moveVector.z = Input.GetAxis("Vertical") * walkSpeed;
controller.Move(moveVector * Time.deltaTime);
}
}