x


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.

more ▼

asked Jan 30 '11 at 04:11 AM

Adam 10 gravatar image

Adam 10
27 14 15 16

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Jan 30 '11 at 04:22 AM

Jessy gravatar image

Jessy
17.9k 78 101 205

Yeah, I just found that out, I think I have it close, I will post my solution when I get it. Thanks.

Jan 30 '11 at 06:38 AM Adam 10

So, I took the LookAtMouse script from the Wiki and then instead 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.

Jan 30 '11 at 10:34 PM Adam 10
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x187
x118
x1

asked: Jan 30 '11 at 04:11 AM

Seen: 1121 times

Last Updated: Jan 30 '11 at 04:11 AM