Third Person Camera

hi,
I already have a camera that works the way i want in my third person game, the only thing it’s missing is that it places itself before an object when that object blocks the view.

I tried to find the code for it in your file, but i coudn’t make it work for my camera, is there a simple way to add this feature to my existing camera?

The script avoids obstacles by casting rays both forward and backward. If a ray hits an obstacle, the camera is moved accordingly. You can see the relevant code in the script with comments indicating what each section does. You won’t be able to just copy and paste it into your script though. You’ll have to modify it to match your own implementation.

This is pretty cool. Easy to implement, so far. Thanks for your hard work, and dedication. :slight_smile:

Hello!
I’m having some problems with this script, when I active to display the cursor, it is always moved to the center, is to make the cursor can move even with the active script?

Here you go.

3rdPersonCamera_FreeMouse.blend (107 KB)

thank you!

Thanks Mobious! for your great work is always a benefit for us , thanks !!

Thank you, Mobious. I am forever grateful for the script. However, I am having some problems.

If the player object goes back towards a wall, the camera detects the wall and zooms into the player, which is perfect. However, as soon as the player reaches it’s movement limit (the moment it starts pushing against the wall), the camera escapes the wall, and goes out of the map. How can this be fixed?

The easiest way without making significant modifications to the script would be to just set the MIN_DIST constant (near the top of the script) to 0. You’ll also probably also need to disable the horizontal camera movement by setting HOR_OFFSET to 0 since I didn’t implement a cap for that.

I have aproblem when i change scenes it tells me that in line 118 an information has been freed already. I am actually working on a 3d open world game where it is necessary to change scenes, because it requires a lot of performance and it would simply be impossible to play if i merge every room into one scene. I tried copying the objects and the scripts and after a few hours of work i got it to work after switching scenes for once, but once i moved back into the first scene the camera script didnt work again. How do i make it work with every scene? Thanks a lot, i really appreciate this script, it’s awesome.

Moving the scene and player variables (defined at lines 27-28) inside the main() function should fix the problem.

Oh my gawd, thanks so much, i’ve had trouble with this since 5 days and the solution is so easy LOL.

That seems to work very well, thank you. But there is a new problem now. The camera does not escape the walls now, and that’s working well, but when it does zoom into the player upon collision, I can see the camera pass through the wall (the faces of the wall come into view and obstruct view of the camera). How can I stop the wall from showing up, just like it was in the previous setup (before the camera escaped the walls)?

Unfortunately with the way the script is designed to allow free camera movement at all times, there isn’t really a simple way to ensure the camera will never briefly clip through walls. There are very few games (even among AAA titles) that completely eliminate camera clipping. To mitigate the issue, you should have all you walls use the Backface Culling option under Material -> Game Settings. This will allow you to see through walls if the camera ends up on the wrong side of them.

what about using a offset value that is deviated by a ray, and the ray uses the mouselook value to check where the camera will be NEXT frame, rather than the current frame?

also, what if you use a offset point that is averaged against the ray hitPoint distance? so the camera floats to where it needs to be, but if there is a obstacle the rate of motion increases? (lerp rate?)

Yes, I ended up enabling Backface Culling and making some other modifications, similar to what you just outlined. Thanks anyway.

How do i stop zoom in and out ? like turn it off.

You can set ZOOM_STEP near the top of the script to 0.

Woah i did not expect you to reply that quick.
I was wondering is there a way to use this like resident evil, more like resident evil 4.
Where you can`t look around, only collision detection ? thank you for such a good script.

I’m not entirely sure what you mean. If you want you can remove the mouse controls and camera positioning from the script and make the camera copy the player’s rotation, but you’ll have to implement that yourself.