Jump to content

Unity Camera Roll

werto165

So im following this tutorial: http://unity3d.com/learn/tutorials/modules/beginner/physics/assignments/brick-shooter
 
I am trying to make it a little more complex by adding in camera rotation(this is using a the right stick on the Xbox 360 controller) , i just want it to rotate left and right, upward and downward. But my issue is this: when I put the controller stick to 45 clockwise to the north for example, the camera starts to roll(which i dont want). 
 

using UnityEngine;


using System.Collections;
 
public class Shooter : MonoBehaviour {
 
public Rigidbody projectile; 
public Transform shotPos; 
public float shotForce = 1000f; 
public float moveSpeed = 10f;
public float rotationSpeed = 50f; 
 
void Update () {
 
float h = Input.GetAxis ("Horizontal") * Time.deltaTime * moveSpeed; 
float v = Input.GetAxis ("Vertical") * Time.deltaTime * moveSpeed;
float hRS = Input.GetAxis ("RightStickHorizontal") * Time.deltaTime * rotationSpeed; 
float vRS = Input.GetAxis ("RightStickVertical") * Time.deltaTime * rotationSpeed;
 
transform.Translate(new Vector3(h,v,0)); 
transform.Rotate(new Vector3(vRS , hRS , 0));
 
if (Input.GetButtonUp ("Fire1")) 
{
Rigidbody shot = Instantiate(projectile, shotPos.position, shotPos.rotation) as Rigidbody; 
shot.AddForce(shotPos.forward * shotForce); 
}
 
}
}

 

Notice the roll. 

6dd02b163b.png

This is how i want it: 

56ef8cfe5b.png

 

Is it just something fundamentally wrong with my code, if so what? Any help would be much appreciated :D

CPU: Intel 3570 GPUs: Nvidia GTX 660Ti Case: Fractal design Define R4  Storage: 1TB WD Caviar Black & 240GB Hyper X 3k SSD Sound: Custom One Pros Keyboard: Ducky Shine 4 Mouse: Logitech G500

 

Link to comment
Share on other sites

Link to post
Share on other sites

xyz is the order of input. maybe i am wrong but wouldnt you want hRS for x, vRS for y, and then 0 for z. depending on the graphics orientation of unity. but i think they have it set so that y+ is up

Link to comment
Share on other sites

Link to post
Share on other sites

xyz is the order of input. maybe i am wrong but wouldnt you want hRS for x, vRS for y, and then 0 for z. depending on the graphics orientation of unity. but i think they have it set so that y+ is up

Almost, xyz directions are individually set per object. But for a camera, it would be silly to not set y as up/down
Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Does the projectile somehow hit the camera and move it?

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Does the projectile somehow hit the camera and move it?

There are no rigidbody physics on the camera itself, it has no part of the overall physics engine so I doubt it. I tried commenting out the fire animation and it did nothing, anyway thanks for the suggestion. 

CPU: Intel 3570 GPUs: Nvidia GTX 660Ti Case: Fractal design Define R4  Storage: 1TB WD Caviar Black & 240GB Hyper X 3k SSD Sound: Custom One Pros Keyboard: Ducky Shine 4 Mouse: Logitech G500

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×