Jump to content
  • Advertisement
Sign in to follow this  
captain_crunch

Camera problem when mixing 2d and 3d

This topic is 3509 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

I have a top-down game with a tilemap which is drawn using sprites. Scrolling is permitted along the x- and y-axis. On top of the tilemap I have 3d models representing vehicles. I have succesfully set up a 3d camera that follows the '2d camera' so that the 3d models stay inside their tiles when the player scrolls. The 3d camera is looking straight down the z-axis, using an orthogonal perspective. Now, however, what I'm really after is a view that is partially from the side, partially from the top. To implement this, I displace the 3d camera position a bit along the y-axis, while having the aimpoint stay the same. But the problem is that now the models start to drift outside their designated tile positions in the y-direction! They are only positioned correctly when they are in a certain portion (at the top) of the viewport/screen. What could be wrong about this setup? I'd appreciate any suggestion. I can also provide code if necessary. A fix I would rather not have to make is to go back to a straight top-down camera and draw every 3d model partially tilted on its side.

Share this post


Link to post
Share on other sites
Advertisement
Alright, I think I have it.

I set the model's position in world space as before (by multiplying the tile position with the tile dimensions). This position coordinate is used in all movement code and anything else.

But when rendering the model, I need to compensate for the distortion shown in the diagram. I do this by multiplying the y-position with a factor based on the distance from the camera target point. Trigonometry was useful here...

Here is the code:

float yDistanceFromCameraTarget = Location.Y - CameraTarget.Y;

float correctedYLocation = (float)(CameraTarget.Y + yDistanceFromCameraTarget / Math.Cos(MathHelper.PiOver2 - CameraViewingAngle));


Now the models are drawn exactly where I want them!

Share this post


Link to post
Share on other sites
I am also planning to convert my 2d tile based game with this 3d effect. Is your project written in XNA? Is this game going to be open source? I am glad that you are sharing this info after you figure out the method.

Share this post


Link to post
Share on other sites
your project looks really interesting. I hope you can get this done soon. Do you have any demo or video to show your progress so far? Good luck with your project.

Share this post


Link to post
Share on other sites
Well, this is an ambitious project and I can only work on it in my spare time. So it will take a while before it is done.

But I will post some more art soon and hope to make a video before/around the end of the year.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!