Sign in to follow this  

Orbital camera help XNA

This topic is 2789 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im just learning XNA and im making a game where i need the camera to orbit about 100 points up and 80 points behind a point on the ground. I also need to be able to move the camera. The code i have so far doesnt work very well, i can move the camera left right up and down fine but when i go to rotate the camera around the point it doesnt orbit the way i want it to. Heres the code: Public Overloads Overrides Sub Update(ByVal gameTime As GameTime) 'MOVE If Keyboard.GetState.IsKeyDown(Keys.Left) Then Dim CameraRot As Matrix = Matrix.CreateRotationY(Rotation) Dim addvec As Vector3 = Vector3.Transform(New Vector3(1, 0, 0), CameraRot) Position += addvec LookAt += addvec View = Matrix.CreateLookAt(Position, LookAt, New Vector3(0, 1, 0)) End If If Keyboard.GetState.IsKeyDown(Keys.Right) Then Dim CameraRot As Matrix = Matrix.CreateRotationY(Rotation) Dim addvec As Vector3 = Vector3.Transform(New Vector3(1, 0, 0), CameraRot) Position -= addvec LookAt -= addvec View = Matrix.CreateLookAt(Position, LookAt, New Vector3(0, 1, 0)) End If If Keyboard.GetState.IsKeyDown(Keys.Up) Then Dim CameraRot As Matrix = Matrix.CreateRotationY(Rotation) Dim addvec As Vector3 = Vector3.Transform(New Vector3(0, 0, -1), CameraRot) Position -= addvec LookAt -= addvec View = Matrix.CreateLookAt(Position, LookAt, New Vector3(0, 1, 0)) End If If Keyboard.GetState.IsKeyDown(Keys.Down) Then Dim CameraRot As Matrix = Matrix.CreateRotationY(Rotation) Dim addvec As Vector3 = Vector3.Transform(New Vector3(0, 0, -1), CameraRot) Position += addvec LookAt += addvec View = Matrix.CreateLookAt(Position, LookAt, New Vector3(0, 1, 0)) End If 'ROTATE If Keyboard.GetState.IsKeyDown(Keys.A) Then 'UP 100, Rotate, Back 5 Rotation += 0.01 Dim TransVec As Vector3 = Vector3.Transform(LookAt, Matrix.CreateTranslation(0, 150, -100) * Matrix.CreateRotationY(Rotation)) Position = TransVec View = Matrix.CreateLookAt(Position, LookAt, New Vector3(0, 1, 0)) End If If Keyboard.GetState.IsKeyDown(Keys.S) Then Rotation -= 0.01 Dim TransVec As Vector3 = Vector3.Transform(LookAt, Matrix.CreateTranslation(0, 150, -100) * Matrix.CreateRotationY(Rotation)) Position = TransVec View = Matrix.CreateLookAt(Position, LookAt, New Vector3(0, 1, 0)) End If MyBase.Update(gameTime) End Sub My game is written in vb.net but it shouldnt be too hard to figure out whats wrong with it, any help would be awesome!!!

Share this post


Link to post
Share on other sites

This topic is 2789 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this