How to prevent camera from clipping through floor? (UPBGE)

I have added a camera with a spherical empty to my model to view all angles, but the problem is that when I look up (during gameplay), the camera ends up below the floor (due to parenting), hence obscuring vision. Is there a way to prevent the camera from going through the floor? Thanks.

Cam example.blend (1.1 MB)

its really up to you. swtor stops the “empty” rotation at horizon, then starts rotating the camera itself to allow looking up. or you can have the camera move closer to the player as you look up (i do this), or stick with a simple raycast camera colider for a more generalized solution

Hello Daedalus, how would you go about doing this? Could you show me or edit my blend file camera if possible? Thank you!

I have followed multiple guides but none seem to work. Any advice you can give on how to achieve this?

Didn’t looked into the file (don’t use UPBE) but nevertheless here are some ideas. Maybe:

  • If the ground is just a plane: constraint the angle to the max which isn’t clipping (maybe “slow down” the movement by a factor?).
  • Maybe don’t rotate with pivot point of the sphere but rather the camer itself?
  • Maybe mix the first two?
  • If ground is more than a plane: adding a sphere at the camera with is following the player but has its own collission testing…

(1) The issue with this is that I am working on a game which would require you to look at the sky.
(2) I would want the view fixated on the character so I wouldn’t prefer this.
(4) I tried this but it still clips through the floor, and even if it doesn’t I would want the camera to get closer to the character when it detects a collision (my knowledge on programming camera rays is lacking).

Hopefully a solution pops up…

Vertex Parent an empty to the player: camera_hook
parent the camera to the camera_hook
write a script so the cam hook can detect if it’s near floor then stop the empty and set it’s position to nearest hit location.

got working example here:

1 Like

Thank you for your work Cotaks, this is very useful. Is there a way for the camera to not pan over when stationary/in general?

yeah read the OP below the download links, i added a solution for the camera drift there, you should also strip down my blend, remove the overlay scenes in 0.2.5, before you use it in 0.3.0 so that you don’t have wasted trash in your blend. the keybinds do not work in 0.3.0 due to 0.3.0 has no overlay and i don’t know when i got time to convert the blend to 0.3.0.

So best is to strip it first, or just use it, it’s your choice, it works anyway, just not the option to set keybinds.

1 Like

On the OP you suggest turning off slow parent to remove “shifting”, but none of the objects on the file have slow parent on (I am using UPBGE 0.2.5). Thanks.

collapse my above post, i tell ppl for 0.3.0 change the script.

in 0.2.5 all is working no changes needed

Hello Cotaks, I’ve noticed that when moving up a slope the character gets launched into the air, and has no control over movement during the process. Would it be possible to stay on ground while travelling on a slope and move like normal mid-air if falling off it?

how you get launched? if you run up a slope and run of then yeah you keep some momentum while falling down. that’s real not a ‘launched into air’

uhm while you walk up as slope you stay on the slopes ground? or what you mean?
moving while in air no thats not realistic haha, but you can change the script, and adjust the groundsensor in the scrip, so you can let it check for ground when you only jump, this makes you able to move in air. but i guess if you do that you will get launched of slopes.

  1. If you increase the walk_speed game property (to 18 for example), the moment you make contact with the slope you get launched in the Z+ direction, is there a fix for this?

  2. I was wondering if it would be possible to glide while falling? e.g. for a winged character.

  1. first of all 18 is fast, humans do like 5 k/h as walk speed, but no it’s just how the physics engine works.
  • you can see if increasing gravity helps. or script something so when you are in air gravity or -z force pulling you down.
  1. no not out of the box, you need to script it yourself. also here you can make a check to see if you are in air then apply a +z force to the character to make it ‘glide’
1 Like

I see, that’s a shame. One of the things I like about the script is that when in forward motion, the direction you look dictates the direction of movement. Can this be achieved via logic bricks? (perhaps using different states?). Or is there a basic script I could incorporate into my original posted file. Thanks

i have no clue if it is possible with bricks, i don’t use bricks, well only the basic needed bricks.

1 Like