- Home /
Look at mouse cursor without flipping
I have this script:
var lookTarget : Vector3;
function Update() {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)){
lookTarget = hit.point;
}
transform.LookAt(lookTarget);
}
I have it attached to my player but when I move the cursor closer to my player it will flip around. How do I fix this?
Comment
Best Answer
Answer by AlucardJay · Mar 27, 2012 at 08:30 AM
It is possible that your Raycast hit Y-axis is lower than your character Y-axis. Try this (untested):
lookTarget = Vector3(hit.point.x, transform.position.y, hit.point.z);
Your answer
Follow this Question
Related Questions
Looking at the mouse cursor... 1 Answer
Make player look at pointed target 1 Answer
How to look at enemy 2d 3 Answers
How to project the mouse cursor into 3D space for LookAt? 1 Answer
Smooth look at on Y axis only 1 Answer