How to snap camera to a collided object using raycasts

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By minemaster552

So i’m making a pretty regular game and sometimes using a tutorial and adding my own little additions using things i learned but i think i didn’t learn enough.
So i’m trying to add a feature where the Camera "snaps towards the enemy center for easier control but my script doesn’t seem to work

func _process(_delta):
if is_colliding():
	var collider = get_collider()
	if collider.is_in_group("enemies"):
		print("Ping! Looked at" + collider)

I will be honest that i seriously don’t know what could be wrong, although the print doesn’t actually print so that could be where the problem is

:bust_in_silhouette: Reply From: Lola


Raycasts are disabled by default (they don’t report collisions) which means you have to enable them explicitly by setting enabled = true either via code or the editor.
Also, note that

  1. collider is an Object and not a String so you can’t do get_node(collider): you should directly use collider.
  2. you can use get_parent() to get a node’s parent rather than doing $".."