- Home /
Character snap to camera direction
Hi!
I was wondering if anyone could help me as I'm a bit of a noob with scripting :D
I want my character to snap to the direction my camera is facing.
Here is the script I have so far for making the character move
using UnityEngine; using System.Collections;
public class Character_Move : MonoBehaviour { public float speed = 100.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);
}
Any help would be greatly appreciated :D
Thank you in advance
Comment