Collision.collider resulting in an error.

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

Hello, i am trying to detect collisions in godot, but whenever i use collision.collider i get an error. I don’t get why this is happening so help would be appreciated.

Here is my code if it would help:

extends CharacterBody2D

@export var move_speed = 100
@export var jump_force = 120
@export var gravity = 1000
@export var max_gravity = 200
@export var move_accel = 800

@onready var sprite = $AnimatedSprite2D

var jumps_made = 0
var max_jumps = 2

func _physics_process(delta):
	var direction_x = sign(Input.get_action_strength('d') - Input.get_action_strength('a'))
	
	velocity.x = move_speed * direction_x
	velocity.y += gravity * delta
	
	if velocity.y > max_gravity:
		velocity.y = max_gravity
	elif is_on_floor():
		velocity.y = 0
	
	if Input.is_action_pressed("space"):
		velocity.y = -jump_force
	
	if direction_x == 0:
		sprite.play('idle')
	elif direction_x == 1:
		sprite.play('move_right')
	elif direction_x == -1:
		sprite.play('move_left')

	
	move_and_slide()
	for i in get_slide_collision_count():
		var collision = get_slide_collision(i)
		print(collision.collider) <-- this results in the error

Can you give us a clue as to what the error is?

SteveSmith | 2023-01-02 12:52

:bust_in_silhouette: Reply From: SteveSmith

Change the line to print(collision.get_collider())

thank you! it works now.

tomatosauce | 2023-01-02 14:08