Hi guys im new to scripting and i need help i want to make the camera rotate around the Y-axis when i press the right mouse button and when released it stays still can some one plz help.
Thanks
Hi guys im new to scripting and i need help i want to make the camera rotate around the Y-axis when i press the right mouse button and when released it stays still can some one plz help.
Thanks
You say "rotate around the Y-axis", but you don't say which Y-axis
Local y-axis rotation:
RightMouseRotate.js (Attached to camera);
var speed : float = 5.0f;
function Update() {
if(Input.GetMouseButton(1))
transform.eulerAngles.y += Input.GetAxis("Mouse Y") * speed;
}
World y-axis rotation:
RightMouseRotate.js (Attached to camera);
var speed : float = 5.0f;
function Update() {
if(Input.GetMouseButton(1))
transform.RotateAround(Vector3.zero, Vector3.up,
Input.GetAxis("Mouse Y") * speed);
}
You also don't specify how you want it to move. The above was based on mouse input. The following is automated movement:
Local y-axis rotation:
RightMouseRotate.js (Attached to camera);
var speed : float = 30.0f;
function Update() {
if(Input.GetMouseButton(1))
transform.eulerAngles.y += Time.deltaTime * speed;
}
World y-axis rotation:
RightMouseRotate.js (Attached to camera);
var speed : float = 30.0f;
function Update() {
if(Input.GetMouseButton(1))
transform.RotateAround(Vector3.zero, Vector3.up,
Time.deltaTime * speed);
}
Check this for Rotating an object: http://unity3d.com/support/documentation/ScriptReference/Transform.Rotate.html
Check this for getting Input and identifying them:
Try this:
void Update()
{
if ( Input.GetMouseButton( 1 ) )
{
Camera.mainCamera.transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
}
}
Regardless of which Y axis we want to rotate around, transform.Rotate is the way to go. Either use
`transform.Rotate(speed*Time.deltaTime);`
or
`transform.Rotate(speed*Time.deltaTime, Space.World);`
for local or global rotation, respectively. Or for rotating around something, use what diabloroxx said, because that individual is an intelligent individual.