Hi
I have written a script that makes my character move. However, I would like the character to face which ever way the camera is pointing
Here is the script:
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var distance : float = 5;
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;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
I have tried using
moveDirection = transform.LookAt(transform.position + Vector3(Camera.forward.x, 0, Camera.forward.z));
to make the character face the direction of the camera but no luck ![]()
Any help would be amazing!