Hi all, I use the following script to make the player rotate to look at the mouse position. However, my model needs to be rotated a little to compensate on a couple of animations so I would like to have a float offset that I can use to adjust the rotation either + / - its set value from the mouse position.
I have created a public float, I just cannot figure out how you apply it in the code that rotates the player model.
Here is the code, please can someone help me?
using UnityEngine;
using System.Collections;
public class PlayerTurn : MonoBehaviour {
Rigidbody playerRigidbody;
int floorMask;
float camRayLength = 100f;
public float offset = 0.0f;
void Awake()
{
playerRigidbody = GetComponent<Rigidbody>();
floorMask = LayerMask.GetMask("Floor");
}
void FixedUpdate ()
{
Turning();
}
void Turning()
{
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit floorHit;
if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
{
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
playerRigidbody.MoveRotation(newRotation);
}
}
}