- Home /
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.
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.
Answer by AngryOldMan · Mar 16, 2011 at 08:20 PM
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)