Help! Code doesn't work as expected

I am getting strange behaviour with the gamble code. The side to side mouse works fine but up/down just raise and lowers the right hand side of the horizon giving a slew view. I have checked the code and it is the same as the lecture, restated everything, and checked the the script is attached only to the parent

here is the code

// Update is called once per frame
void Update () {
float rotationSpeed = 5.0f;
float mouseX = Input.GetAxis (“Mouse X”) * rotationSpeed ;
float mouseY = Input.GetAxis (“Mouse Y”) * rotationSpeed ;

	// can use getcomponent for this but there is a 
	// transform object pointer created by default
	transform.localRotation = Quaternion.Euler(0,mouseX,0) * transform.localRotation;
	Camera camera = GetComponentInChildren<Camera>();
	camera.transform.localRotation = Quaternion.Euler(-mouseY,0,0) * camera.transform.localRotation;


Code looks to be OK at first glance, so could you perhaps upload a zip of the entire project?

Thanks for the reply - I can’t upload a zip here as it says it will only take .jpeg etc. Any idea on how I can get the zip to you ?

You could try something like Dropbox perhaps? They offer free accounts and it’s pretty quick to get signed up and started

Apparently, how the camera rotates under localRotation via quaternions is also sensitive to your initial position and orientation of your camera in the scene tab.

I picked this up from the Q&A as soon as I set the rotation back to 0,0,0 it worked fine. I guess its something to do with how euler rotations are non communicative

Good stuff :slight_smile: I’m glad you found a solution.

I had this same problem. To reiterate on Bob’s solution, make sure your rotation on the main camera’s inspector is set to (0,0,0).

This solved my problem too so many thanks for this.

Hi everyone!

I have my code perfectly matching with the one on the Lecture, although I am experiencing unexpected behavior. The camera-gimbal is working fine, the issue is that the ball are been launched always from the same spot and direction.

I checked the hierarchy, if the scripts were on the right place and etc… It is all looking good.

Please help to find what is wrong here.


I had problems too, the camera was rotating wrong…then I realized I forgot to move the script component from the camera to the player object. Now works prefect :wink:

Privacy & Terms