- Home /
Question by
YayGee · May 16, 2013 at 05:49 PM ·
rotationrotateplatformer
Rotating towards the mouse.
I copied this script from a Youtube tutorial that I watched. The script basically made it so that the front of a game object is pointing towards the mouse by rotating. But the script is created in a way that it only rotates the X and Z, so you needed to have the camera flying over the player pointing downwards for it to work. I am currently working on a platformer and I want to use this script in it, but because I only can rotate it from X to Z, or the other way around, It doesn't work! I want it to spin from X to Y! Here is the script:
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hitdist = 0.0;
var targetPoint = ray.GetPoint(hitdist);
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
function Update () {
if (playerPlane.Raycast (ray, hitdist)) {
transform.rotation = targetRotation;
}
}
ps: it doesn't work rotating the object 90 degrees towards the camera.
Comment