x


Rotate Cube towards Mouse position

Hay Guys, I'm currently in the process of writing a simple movement system. As you can see from the attached image, the main camera is looking over the cube. alt text

I have wrote the following script which basically moves the cube forward (with varying speeds)

var walk_speed : int = 30; var run_multipler : float = 1.5;

function Update () { if( Input.GetKey("w") ){ move_speed = walk_speed; if( Input.GetKey( KeyCode.LeftShift ) ){ move_speed = walk_speed run_multipler;
}
transform.Translate(0, 0, ( Time.deltaTime
move_speed )); }
}

How do i implement a "rotate towards mouse". Wherever the mouse is pointing, the cube will rotate towards that point.

more ▼

asked Mar 16, 2011 at 08:07 PM

kevdotbadger gravatar image

kevdotbadger
66 27 17 23

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

2 answers: sort voted first

some thing like Input.mousePosition http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html take a look at some of the basic tutorials http://unity3d.com/support/resources/tutorials/ im sure one of them has a script similar to what you want. (try the FPS)

more ▼

answered Mar 16, 2011 at 08:20 PM

AngryOldMan gravatar image

AngryOldMan
2.7k 37 36 67

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

answered Mar 16, 2011 at 08:41 PM

DaveA gravatar image

DaveA
33.6k 419 346 487

(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:

x1473
x1200
x377

asked: Mar 16, 2011 at 08:07 PM

Seen: 3619 times

Last Updated: Mar 16, 2011 at 08:07 PM