- Home /
rotate player towards the mous
hey, i make a new little game, in which i want my character always to look at my mouse. and i also want to have a GUI on my mouse so i can actually use my mouse as the controller for the character.. i got the normal move script from the documentation so far...
Answer by potatum · Nov 06, 2010 at 07:54 PM
look ans shoot at mouse:
var speed = 4.0;
function Update () {
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if (playerPlane.Raycast (ray, hitdist)) {
var targetPoint = ray.GetPoint(hitdist);
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
}
}
cursor:
var cursorImage : Texture;
function Start() { Screen.showCursor = false; }
function OnGUI() { var mousePos : Vector3 = Input.mousePosition; var pos : Rect = Rect(mousePos.x,Screen.height - mousePos.y,cursorImage.width,cursorImage.height); GUI.Label(pos,cursorImage); }
sorry but this is not working! i saved the script for the character out into a new script and put it on a sphere... and it does nothing! but thanks anyways!