fbpx

 

Third Person Camera...
 

Third Person Camera - Collision  

   RSS

0

Hi,

So I've been working a lot on my third-person camera and it's working pretty nicely. I have recently been trying to get camera collision working to stop the camera from clipping through the game world. I have this partially working. If I do indeed clip into an object it zooms me out. However, this zoom often involves going directly through the object in the way, causing clipping. Ideally I want it to completely avoid going into the object. My current code is below:

https://pastebin.com/mH5gafuF

Does anyone have a suggestion for fixing this issue. I thought maybe I could add a collider to the camera? Would that generally be seen as an efficient way of fixing this?

Any advice and improvements wouldn't be gratefully received.

Ninja

1 Answer
0

from looking at your script @knowitallninja I would suggest here

  1.  float ViewObstructed() {
  2.         float hitDistance = 0;   <<<< (Set this to a little farther away than 0 maybe a 0.5f)
  3.         RaycastHit hit;
  4.         if (Physics.Raycast(target.transform.position, transform.position - target.transform.positionout hit, 3f)) {
  5.             if (hit.collider.gameObject.tag != "Player") {
  6.                 hitDistance = _desiredDistance - hit.distance;
  7.             }
  8.         }
  9.         return hitDistance;
Share:

 

 

Scroll to Top

Please Login or Register