- Home /
Camera/mouse movement issues "almost but no dice"
I am having some issues with this code. It works fine if the mouse cursor is on the bottom half of the screen but as soon as its moved to the top have it goes wherever it wants.
Thanks for the help.
var lookTarget : Vector3; var turnSpeed = 20.0;
function Update() {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; if (Physics.Raycast (ray, hit)) { lookTarget = hit.point; }
// rotate towards target var lookDelta = (hit.point-transform.position); var targetRot = Quaternion.LookRotation(lookDelta); var rotSpeed = turnSpeed * Time.deltaTime; transform.rotation = Quaternion.RotateTowards( transform.rotation, targetRot, rotSpeed );
}
Answer by Dreamer · May 12, 2011 at 06:12 AM
Set tag of your terrain to "Terrain"
var lookTarget : Vector3; var turnSpeed = 20.0;
function Update() {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; if (Physics.Raycast (ray, hit)) { if(hit.collider.tag=="Terrain") lookTarget = hit.point; }
// rotate towards target var lookDelta = (hit.point-transform.position); var targetRot = Quaternion.LookRotation(lookDelta); var rotSpeed = turnSpeed * Time.deltaTime; transform.rotation = Quaternion.RotateTowards( transform.rotation, targetRot, rotSpeed );
}
Still Nogo. It will work fine if the mouse cursor is on the lower half of the screen. If the cursor is above 60%ish of the screen it will rotate to a fixed spot every time. tried to tag everything properly but not sure if I did that right. but with the tag and code change nothing happened. thanks for the help
Your answer
Follow this Question
Related Questions
Top down movement and rotation 2 Answers
Erratic movement problem 2 Answers
How to select one prefab from more ? 0 Answers
How can I produce the typical FPS mouse steering effect? 2 Answers
Move a cube with mouse relative to the camera rotation 0 Answers