Hey I’m looking to make a controller for my third person shooter, but I keep running into problems when I try to have bones in my character look at a target. I have an object in my scene called “Aim Target” and that is what the camera always points to. I need my characters upper body to point to this as well, but using LookAt on bone transforms doesn’t seem to be the way to go. I’ve looked at the Third Person Shooter example, but I have no idea how to implement it into my project.
This is what I have so far:
using UnityEngine;
using System.Collections;
public class CharacterControls : MonoBehaviour
{
public float speed = 12.0F;
private Vector3 moveDirection = Vector3.zero;
public Transform aim;
public Transform follow;
void Update()
{
transform.LookAt(follow);
CharacterController controller = GetComponent<CharacterController>();
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if(Input.GetAxis("Vertical") < 0)
{
moveDirection *= .5f;
}
controller.Move(moveDirection * Time.deltaTime);
this.transform.position = new Vector3(transform.position.x, 0, transform.position.z);
}
}
This works well for WASD movement and for camera horizontal, but I need help with the vertical rotations of the character. Thanks!