best method for FPS collisions?

Blitz3D Forums/Blitz3D Beginners Area/best method for FPS collisions?

andy_mc(Posted 2010) [#1]
I'm writing an FPS engine and am currently using a camera, with a parent pivot in teh middle of a sphere which I use for collisions. I use sliding collisions between the sphere and polygons, so the sphere will go up stairs if the stairs are shallow enough but obviously my camera goes up through objects (like the ceiling) if I go too high. What's the best and most simple method for an FPS camera?


Rob the Great(Posted 2010) [#2]
Are you actually using a sphere for collisions? If so, it would probably be more efficient to use EntityRadius() for the camera and get rid of the sphere entirely, as it will do the exact same thing. Using this method, the collision detection should be more accurate and consume less resources. Unless there's a specific reason why you need the sphere, EntityRadius() will make it easier on you.

I'm not quite sure what you mean about the camera moving through the ceiling. Do you have sample code?

Here's some pseudo code about what I'm talking about:

;Set up your Graphics and Whatnot

;Create a camera with EntityRadius applied
camera = CreateCamera()
EntityType camera,type_camera ;Haven't set the constant 'type_camera' previously, this is for example only.
EntityRadius camera,10,15 ;Set's a 'sphere' with a size of 10 in x, 15 in y around the camera. You can play around with these values to match the size of your original sphere.

;Load the level
level = LoadMesh("YourLevelHere.b3d")
EntityType level,type_level ;Example only, be sure to set the constant 'type_level' before this

;Do collisions
Collisions type_camera,type_level,2,3

;Main loop here
While Not KeyDown(1)

;run your program

RenderWorld
UpdateWorld
Flip

Wend
;End the main loop
End

To me, this is the easiest way to perform collisions on a camera.


John Blackledge(Posted 2010) [#3]
I would seriously recommend that you stick with the sphere (or preferably pivot) as the player, and the camera parented, say, 1.5 units above.

I've tried many methods, but this is always the most adaptable.

Another thing to consider is that to get your camera at the required height above the ground will mean that a (camera-only) camera radius will be just as wide, and the diameter will be double that - easy to walk up stairs if they're wide enough, but you won't be able to walk through doorways.


puki(Posted 2010) [#4]
Yeh.

1.5 units may be a tad too small if you are scaling the world - I put my camera at 1.72 which would be the eye height of an average adult male.

I always parent to a pivot. You can then always parent an alpha'd mesh (stretched cube) to the pivot to give it additional substance for collisions - this is like an upper body, you don't extend it to ground level - the point of not doing that is so that you don't collide with absolutely everthing on the floor, etc - it is more of a knee/thigh height to chest height collision system - so, the pivot is what keeps you from falling through the floor/counters gravity and your collsion mesh works independently.

With stairs, most people will put an alpha'd flat mesh on the stairs (or slightly in the stairs) to allow the player to climb the stairs without having to make the stairs smaller. Your other option is a collison check for a stairs entity then switching the player into a stair climbing phase. Again, your collision system can be dynamic with doors - you can detect the collison with a door type, then switch the collsion system to allow you through the door and then carry on as normal.

Just bare in mind that you can use more than one collision system for different scenarios, rather than trying to find one system that works well for most of the time.


Shambler(Posted 2010) [#5]
Back in the days that I used to program ( some may remember my SARE engine)...or maybe not, I think the best controller design to use is a lollypop.

That is, a small collision enabled sphere on top of a linepick, the linepick sets the height of the sphere.

This allows you to,

1) walk up stairs easily without adding extra geometry to your level i.e. a slope over the stairs. The linepick detects the raised stair and the sphere is raised using linear interpolation to the new height.
2) crouch by adjusting the length of the linepick and making the player 'fall' down to a lower height relative to the ground when the crouch key is pressed.
3) clamber over low height objects naturally, if the line pick detects a new height under the sphere then the sphere gets raised to stand on top of this new height...this also works for stairs,oh I already mentioned that ;)
4) the sphere is small enough to get through doorways and more importantly, small enough to crawl through something like ducting ala duke nukem/deus ex.
5) if the slope of the geometry underneath the sphere, detected by the line pick, is too steep (check the Y normal) then we can make the sphere fall down the slope by moving it in the direction of the slope normal...the sphere will stagger down the slope rather than slide which is more realistic.

Food for thought.