Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Camera rotation is a little off

Started by Muzzy A 2 replies 1k views
Original Post
Muzzy A
Muzzy A

Hey, I'm trying to get my camera to work right. But I'm having trouble and I can't figure out why.

I've even looked up tutorials and basically copy-pasted the code from the tutorials and it still wont work.

But, I'm trying to do it the way I learned in school.



 
Matrix camRot = Matrix.CreateRotationY(mouseX * dt) * Matrix.CreateRotationX(mouseY * dt);
 
// Rotate like this?
cam *= camRot;
 
// Fix up the broken axis's
cam.Right = Vector3.Cross(cam.Forward, Vector3.Up);
cam.Right.Normalize();
 
cam.Up = Vector3.Cross(cam.Backward, cam.Right);
cam.Up.Normalize();
 
//cam.Forward = Vector3.Cross(Vector3.Up, cam.Right);
//cam.Forward.Normalize();

This code works perfectly fine for rotating left and right, but when I rotate up and down, everything is skewed and awkward looking.

Bacterius
Bacterius

cam.Backward?

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
DonTzzy
DonTzzy


//cam.Forward = Vector3.Cross(Vector3.Up, cam.Right);
//cam.Forward.Normalize();

This help?

cam.Forward = Vector3.Cross(cam.Up, cam.Right);
cam.Forward.Normalize();

Muzzy A
Muzzy A


//cam.Forward = Vector3.Cross(Vector3.Up, cam.Right);
//cam.Forward.Normalize();

This help?

cam.Forward = Vector3.Cross(cam.Up, cam.Right);
cam.Forward.Normalize();

already tried that, made it 1000 times worse, everything basically disappeared.

And the backward thing, i know it's weird, but forward put me facing the opposite direction i actually wanted to be

The way You currently see it,it seems like it's trying to rotate around the world's x axis instead of it's local, but at the same time tries to do it on the local, so i get these really awful and awkward camera angels

But like i said, looking left and right works absolutely fine.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.