- Home /
Update EmptyGameObject Rotation to MousePosition
Why doesn't this seem to work?
function Update (){
if(Input.GetButtonDown("Fire1")){
transform.LookAt(Input.mousePosition);
}
}
This script is attached to the PrefabSpawnPoint I would like to rotate toward where I click on the screen.
This seems to be the simplest solution, but not working.
Answer by Jessy · Jan 30, 2011 at 04:22 AM
Input.mousePosition is not a place in the world; it's a place on your screen.
http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenToWorldPoint.html
Yeah, I just found that out, I think I have it close, I will post my solution when I get it. Thanks.
So, I took the LookAt$$anonymous$$ouse script from the Wiki and then ins$$anonymous$$d of constantly updating the script I just call the function when I click the left mouse button. This rotates my barrel in the direction I would like to fire. This cause me a new problem, but I will ask a separate question. Thanks.
Your answer
Follow this Question
Related Questions
Getting the z of mouse position? 1 Answer
how to make force from mousepointer constant ? 0 Answers
move camera relative to mouse position. 0 Answers
constant fire (transform) 2 Answers
Trouble with script to fire a bullet from a handgun 1 Answer