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 '11 at 08:07 PM

kevdotbadger gravatar image

kevdotbadger
66 8 9 13

(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 '11 at 08:20 PM

AngryOldMan gravatar image

AngryOldMan
2.7k 14 21 48

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

answered Mar 16 '11 at 08:41 PM

DaveA gravatar image

DaveA
32.4k 158 176 278

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

x1308
x1047
x327

asked: Mar 16 '11 at 08:07 PM

Seen: 3204 times

Last Updated: Mar 16 '11 at 08:07 PM