[SOLVED] Chase camera collision with terrain (heightmap)

Do you have an video example of your camera?
I dont know if i get it, is your camera always above head location?

Only when looking down. Then when looking up, its below the head location. So my camera angle is never parallel to the ground, which causes the clipping that you don’t want.

And if I remember correctly, I don’t think I ended up keeping the method of adding the contactNormal as an offset to fix the left/right side clipping in my camera controller code, because it ended up causing a sudden camera jerk when going in and out of detecting a collision, due to adding that small offset. And a larger offset value would reduce the clipping better, but caused more jerkiness like that. So I figured I’d worry about it later on since the clipping I do experience is minimal and rare.

I think here is the key.
My ground is static, so when looking down or up: the camera center is always the Spatial Character and my camera angle is rotated.
What do you mean your camera angle is never parallel to the ground?
Sorry about many questions, but i just cant get this working whetever i do.

In summary I have a height map with mountains and a 3rd person spatial character, and camera is colliding with walls. (i swear i looked in many jme tutorials, but all collide)

https://i.imgur.com/N1cchOT.mp4

For example in my video, the camera direction is not looking forward when it is located on the ground, instead I make it look up.

If the camera is sitting on the ground (like in your screenshot where it detects a collision with the ground) and has a camera direction with a y value close to 0, then the camera view direction is almost parallell to the ground that the camera is sitting on, causing the lower half of the camera to render what is underneath.

2 Likes

Thanks a lot for the video and explanation!

I checked my camera location and almost equals to the ground, and character! (in that ugly print screen) (my terrain is y rotated -100)

targetLocation: (-13.0, -73.357315, 24.0) | cameraLocation:(-10.108667, -72.56084, 24.076254) | lookAtOffset:(0.0, 0.0, 0.0)

maybe should i change cam.lookAt to above head location?

I just change the look at to head location, and now fixed it!!! hahaha this now is not so ugly as the last screen!!

Thanks a lot for helping and patience!


2 Likes

Glad to help and to see you finally got it looking good :slightly_smiling_face:

2 Likes

Thanks so much!

3 Likes

Video 18 seconds.
You can see the camera going through the wall.
A similar problem occurs in my game.

Do you have a solution to this problem?

Im not entirely sure if i can tell by your screenshot, but that looks like a type of wall-peeking strategy that many players will use in competitive games with a 3rd person camera so they can see whats around a corner before exposing their character, and i don’t think theres any way to prevent it, and i also wouldn’t worry about it too much since it ends up being one of those things that players like since it can give them a tactical advantage for knowing how the camera mechanics work.

1 Like

Thank you for your reply :grinning: :grinning: