- Home /
Smart camera?
I need to figure out how to do a camera that avoids the walls like in most games. I've tried everything I could think of including collision, rigidbodys, springs, hinges, and so forth, but I haven't found a method like that yet... I'd really like to know of a method that allows you to throw it together with little to no scripting so it doesn't take so long to add it to lots of things, but I'm willing to do a script if that's what it takes.
Thank you for any help.
unity noob
Answer by jeango · Dec 26, 2012 at 09:37 AM
I was thinking about this the other day. I haven't tried this yet, but I was thinking of the following method (works only if your camera is pointed straight to your player):
Have your camera use a raycast, if whatever collides with your ray is something else than your player (meaning there's an obstacle between your cam and player), reduce the distance between your cam and your player so that the new position of the camera is beyond the collision point.
You could add a minimum distance as well, that would switch to first person camera when the third person camera would be too close (if you're back against a wall or something.
It's just an idea I had the other day, don't know if it will turn out OK though. I can imagine some examples where it would be a problem (like if an enemy comes between the cam and player) but you could always solve that by using collision matrix
Let us know if it works out fine, like I said, it's just an idea I never actually tried this.
Your answer
Follow this Question
Related Questions
Helicopter Crash Collision 0 Answers
RigidBody stuck on wall when jumped against 7 Answers
Addforce to ball in camera position 0 Answers
Spawn rigidbody on collision 1 Answer