Skip to main content
GameDev.net gamedev.net
🔒 Locked

Camera Collision Question

Started by ehmdjii Jan 23, 2007 at 12:58 PM 1 replies 700+ views
Original Post
ehmdjii
ehmdjii
hello, ok, i have a quite difficult problem here.... :-) the character can walk on a tile-based terrain (regular grid). there is a camera behind the character at a fixed distance, which always follows the character. now each of these tiles may be passable or not-passable. now as the character moves around, the static line between the cameraposition and the characterposition may collide with some of these not-passable tiles. when this happens, this camera axis should start to rotate, so that the there is no intersection between this line and any of the not-passable tiles. imagine dragging a pencil through a regular grid, with obstacles on some grid cells. now i am looking for an idea on how to implement that. i hope i could explain the problem sufficient, if not please tell me. thanks a lot in advance!
Wyrframe
Wyrframe
You know the Camera-to-Target line goes from the camera to your player. So, test this line for collision against the world, or more likely against a simplified version of it (the collision hull, not the rendered hull).

For an obstacle to be in the way, the CtT line must intersect two or more polygons; if you set the normals correctly, these normals point out, away from the "solid" of the world. Take the average of all these normals, or perhaps a weighted one (higher weights to those polygons closer to the camera), and push the camera in that direction. Or, unless the player is ascending/descending a slope or ladder, project that direction into the ground plane, and move the camera along that.

Using that offset vector as an acceleration of the camera's movement, and doing a temporal damp on the camera's velocity, will provide much smoother movement of the camera than applying it directly to the camera's position will.

I hope that helps. If it works like the vector math in my head tells me it will, it would be smooth, intuitive, and nifty.

If you're having trouble picturing that, drop me a line at ( tiog shi @ g ma il.co m, drop the spaces ).
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
ehmdjii
ehmdjii
ok thanks a lot! i pretty much got that system running you described.
i am rotating the camera depending on the type of collision with a cell.

the only problem that remains is with corners, where the camera can not escape.
rotating left would lead to a collision AND rotating right would lead to a collision.
in this situation that cameraposition should stay where it is, until the character moves away again, and the camera can be rotated.

the problem i have, is that i can not detect such a type of collision.

thanks

Topic Locked

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

Sign in to reply to this topic.