- Home /
How to rotate an object on one axis facing another object?
So I'm trying to get a gun to rotate up and down on a third person character on the Z axis (that's it's top). but even after a few hours I've been unable to achieve anything at all, anyone got any ideas? The character won't move upwards and downwards so instead i've been trying to just have the gun move along with the camera. As you can tell from the picture, even when the camera is facing upwards it does not move up, only side to side. Most of the things I've tried have resulted in nothing at all or the camera being put at a weird angle, or the gun moving randomly sort of.
This is all I got, none of it works:
#pragma strict
var target : Transform;
function Update () {
//transform.LookAt(Vector3(target.position.x, target.position.y, transform.position.z));
//transform.rotation = Quaternion.Euler(transform.rotation.z, transform.rotation.z, target.transform.rotation.z);
//transform.Rotate(Vector3(0, 0, Input.GetAxis("Mouse Y")) * Time.deltaTime *15);
// if (transform.eulerAngles.z < 90)
// {
// transform.Rotate(0, 0, Input.GetAxis ("Vertical") * 20);
//}
// transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.z, 100, 300);
// if (transform.eulerAngles.z >= 240)
// transform.eulerAngles.z = 240;
//if (transform.eulerAngles.z <= -240)
// transform.eulerAngles.z = -240;
//if(transform.eulerAngles == Vector3(0,30,0) || transform.eulerAngles == Vector3(0,-30,0)){
//Debug.Log("BRO HELP");
//transform.rotation = Quaternion.identity;
}
Thank's in advance, I'm really frusterated and I need it
Your answer
Follow this Question
Related Questions
Rotate according to the camera on Y and Z only! 2 Answers
Is there a way to lock my camera's rotation and movement on certain axis? 2 Answers
Camera rotating with physics based movement. 0 Answers
UI not rotating correctly when in "Canvas mode - Camera", I'm hard stuck on this 0 Answers
Camera rotation around a single axis - following a rolling ball 3 Answers