🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

3rd Person Collision

Started by
3 comments, last by Psychopathetica 5 years, 1 month ago

Hello. Basically I ran into an issue where I have a ball a certain distance in front of a FPS movable camera, basically 3rd person. If the ball hits a wall, it detects the collision, but rather than enacting the collision response, it ends up going through it! Mainly because the object wants to continue being that distance in front of the camera. And my collision code is so precise that no matter how fast the object goes, itll hit the wall no matter what, which is strange.

However, if I just let the ball freely move and hit the wall, the ball collides and does the collision response as it should. I tried looking up 3rd person collisions on Google, but all the articles unfortunately were involving the camera, not the object in front of the camera. Basically the effect Im looking for is if the object in front of you hits the wall, then not only should the object stop and sweep along it, but the camera as well. What can I do to achieve this? Thanks.

Advertisement

First: sphere object collision and camera collision - in most cases is the same sphere collision ..

You say it hits the wall no matter what so here are 2 solutions

- no it doesn't

- you do not attach collision response

The way I did this was make the camera a follow camera. So you are really moving the ball (in my case a character).  All the camera does is obey the "follow camera" rules that it's programmed with. 

You also need some collision for the camera but this would be a different kind of collisions.  My camera has an elevation and azimuth, measured from the front face vector of the character. So as the the player turns the camera turns with it.  So you can kind of imagine a stick from the character to the camera that keeps the camera's relative position to the character. Now, as the character turns and the camera collides with something you simply move the camera forwards along the stick until there is a clear line of sight to the character.  You can do this by checking for collisions in a line from the character back to the desired camera distance along the stick. Once the camera collision is clear (say the character moves again) the camera jumps back along the stick to it's desired distance. When the camera jumps back you can make a it a smooth transition if you don't want to jar you players perception.

So basically instead of having the object's world coordinates be tide to the camera's world coordinates with a distance amount, I should have the camera be pulled by the object instead like a dog on a leash? Interesting idea.

I was also exploring other possibilities in my head such as using velocities. Once the object collides the velocities of both the object and camera can be tied together to move the same. Another thing I was thinking of using would be a large ellipsoid around the object and camera together with the object on one long end and the camera on the tail end, and check for collision on that but I don't think this would end up right. But it was a thought.  

This topic is closed to new replies.

Advertisement