- Home /
Isometric game camera limits
I'm trying to set the limits for the camera of an isometric game I'm trying to make. The problem I'm having right now is that my world objects are placed with 0 rotation made to fit on whole number coordinates on the world, but the camera is rotated 45 to get the classic "sim city" view.
The thing is that I'm checking the limits with a simple 3 component clamp on max and min 3D values, which means that the world "walls" are oblique to the camera view, i.e., the camera can move on a rhombus, not a straight rectangle... is there a way to be able to set up the limits so they work relative to the camera's rotation?
edit: I made this simple diagram:
the red square are the limits, they go from -10,-10 to 20,20 in (x,z), but the camera view is oblique, it looks at it diagonally, like a standard sims-like view. I need my world limits to be not the square that goes from -10,-10 to 20,20 in world coordinates, but the one that goes from -10,-10 to 20,20, in a 45 rotated world, so the camera behaves like this:
where the brown is the floor, and the red is the camera limits
is this clearer?
Answer by NewfieJoe · May 06, 2011 at 12:19 AM
If the camera is rotated at n odd angle and shifting by transform throws it off, make it the child of an empty GameObject aligned to your constraining rectangle and use that as a handle to move it. You can also cheat the constraints by placing it in an offscreen volume and using collision detection to stop it from moving out of bounds if the constraints are an irregular shape. ;)
I tried to do this, but used rigidbodies, and that was just too messy, the camera would bounce against the borders ins$$anonymous$$d of just stopping, I COULD turn off the physics and do a complicated collision detection or an ugly labeling of the walls to know which direction I'm supposed to stop it from moving, but I think this is ridiculous if what I want to do is to clamp it to a rectangle
You're falling into the trap of presenting a "solution" you came up with as a problem, and you're asking how to solve it. You're asking us for a solution to a solution, and you don't even know if it's a solution at all. Forget what you think you know or how you think things should work. Describe your PROBLE$$anonymous$$ and maybe someone will know how to solve it.
I'd upvote your comment. You're absolutely right. Anyways, I realized that if this was a simple problem, we wouldn't need AA.BBs, so I think the elegant solution is to straighten up the camera, and rotate the rest of the world
Answer by flaviusxvii · May 05, 2011 at 08:49 PM
Can you draw a picture of what you're talking about and post it on imgur.com and paste a link. I would think you'd want the camera to only look at the rhombus, which it sounds like you have. I don't know what you mean by a 'straight rectangle'. Straight with respect to the forward direction of the camera? Wouldn't that allow you to view things that are out of bounds?
yes, I want it to look at the rhombus, but its movements to be limited by a rectangle straight to the forward direction of the camera. This WOULD allow me to view stuff out of the borders, but since my level's shape's a cross anyways, this is quite hard to avoid anyways
Answer by Henrique Vilela · May 05, 2011 at 08:54 PM
The way you move the camera are not supposed to be affected by the camera rotation, so the clamp approach should work keeping the camera on a squared limit. The unique difference is that your limit square is not the same as your stage, you need to offset it based on your camera angle and distance from the floor.
Lets say your objects are placed from 0,0 to 100,100. Your camera will be limited by (f.e.) 25,25 to 125,125. The 25 offset is just a guess, the value will depend on your camera's angle and floor distance.
no, I figured that part out. What I want is precisely to clamp the camera to a rectangle rotated in the same way as the camera
Answer by MiguelDeLaCruz · May 05, 2011 at 09:04 PM
you could use the camera's transform.
transform.position += transform.right * Time.deltaTime;
That would move it to its right based on it's rotation.
This I'm doing, and it's working fine, the problem is not with movement, but with the clamping
Your answer
Follow this Question
Related Questions
3D Isometric Camera rotate around player and follow 1 Answer
Forward and back movements with a camera emulating an isometric view 1 Answer
Isometric camera movement 1 Answer
i need to use the rotation value of the x axis on a camera 1 Answer
Isometric - Camera follow an object when at the edge of the screen 1 Answer