3rd person camera collision response

Started by
3 comments, last by Andrew Kabakwu 12 years, 4 months ago
So i've programmed my camera to follow and rotate around the player as it does in most 3rd person games. Now comes the issue of preventing it from becoming embedded in objects. Here is what im planning and im wondering if anyone with experience could comment.

The 'part' of the camera that will be used in the collision detection is the yellow 'rectangle' or the near panel of the viewing frustrum. I figure that if any part of this rectangle is 'colliding' with an actor or environmental object, the the vision will be obstructed. If this assumption is incorrect, please let me know.

clPzY.png


So heres basically what I figure i will do:

1) do a quick boolean intersection test. Is any part of the near 'yellow' panel embedded in an object. If no, leave the camera as is. I with use my GJK-SAT algorithm for this.

2) if the GJK-SAT returns true, it is intersecting. I could either:

  • A) move the camera to the furthest non-intersecting position from the player
  • B) move the camera to the closest non-intersecting position from the player.

iHtfv.png


Im leaning towards option B. I think thats how most game cameras deal with intersections. Either way im doing a swept rectangle test. Except for option B i use the furthest position instead of closest.

What do you guys think? Would this produce satisfactory results? Is there a more efficient way?

Thanks for any help!
Advertisement

Im leaning towards option B. I think thats how most game cameras deal with intersections. Either way im doing a swept rectangle test. Except for option B i use the furthest position instead of closest.

What do you guys think? Would this produce satisfactory results? Is there a more efficient way?

From what point are you intersecting? I'd start from the player and backup until an intersection occurs, that'd be the nearest intersection. I use a sphere instead of a rectangle, easier to handle for me.

From what point are you intersecting? I'd start from the player and backup until an intersection occurs, that'd be the nearest intersection. I use a sphere instead of a rectangle, easier to handle for me.
[/quote]

Okay, that sounds good, im assuming you fit the circle to the rectangle as such:

Ye1De.png
Where the diameter of the circle would be the distance from one top corner of the rectangle to the opposing bottom corner, and centered on the geometric centre of the rectangle?

Also if the player is right up against an obstacle and therefore the camera cannot be placed without being embedded in the player then i would simply not render the character and center the camera on their origin to give a temporary 'first person view'. Most games tend to do that i believe.
Yes that's correct. Another option is to temporarily change the camera angle so that the camera goes up, in most games there's hardly any obstacle that prevents the camera from going up. I went with 'first person view' when the camera gets too close because the camera angle is of significant importance when using the mouse, sudden changes would be very annoying to play with.
Have a look at this 3dBuzz -Unity Custom 3rd-Person Character and Camera System with C#

This topic is closed to new replies.

Advertisement