I’ve looked through previous answers and posts in order to help me to construct a piece of javascript, I’m very new to coding so I’m pretty much making frankensteins out of other peoples scripts trying to get stuff to work and in this case it just isn’t working!
Would be grateful if someone could help me to get this code working properly! It’s supposed to rotate and object in all three axes to face the mouse position, and to do it smoothly instead of jumping immediately to the position.
var speed = 4.0;
var hit : RaycastHit;
function Update ()
{
var ray : Ray = camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray,hit)) {
var targetPoint = ray.GetPoint;
var targetRotation = Quaternion.LookRotation(
targetPoint - transform.position);
transform.rotation = Quaternion.Slerp(
transform.rotation,
targetRotation, speed * Time.deltaTime);
}
}