I do not have a code snippet handy, but from what I remember you can achieve this by sending out a raycast backwards from the player towards the camera, and then if the raycast hits something, set the camera's position accordingly.
This works pretty well and I've used a similar approach in a few games before.
I think in Godot 3.1 there is going to be a camera node that does something similar to this built in, but I'm not 100% sure.
I have also implemented a KinematicBody camera in the jam game I made, Dreams of Fire, which you can find on GitHub. Here is the code for the camera from the jam:
extends KinematicBody
export (NodePath) var path_to_target;
export (NodePath) var path_to_camera_origin;
export (float) var max_length_from_target = 9;
var target;
var camera_origin;
func _ready():
target = get_node(path_to_target);
camera_origin = get_node(path_to_camera_origin);
add_collision_exception_with(get_parent());
get_parent().add_collision_exception_with(self);
func _physics_process(delta):
var relative_vector = (target.global_transform.origin - global_transform.origin);
if (relative_vector.length() >= max_length_from_target):
global_transform.origin += relative_vector;
else:
global_transform = camera_origin.global_transform;
var new_dir_vector = (target.global_transform.origin - global_transform.origin);
move_and_collide(new_dir_vector);
global_transform.basis = target.global_transform.basis;
Looking at it now, I'd probably just use a Raycast, as using a KinematicBody might be a tad overdoing it, but hopefully it can be of some help implementing camera collisions.
Hopefully this helps :smile: