Help with Colliders

Godot Version 4.4

Question

EDIT:
so My code is now

extends CharacterBody3D

func _physics_process(delta: float) -> void:
	# position += transform.basis * Vector3(0,0,-speed) * delta
	var speed = transform.basis * Vector3(0,0,-50) * delta
	self.velocity += speed
	
	for i in get_slide_collision_count():
		var collision = get_slide_collision(i)
		if collision.Health:
			collision.Health -= 1
	
	move_and_slide()

However I get Invalid access to property or key 'Health' on a base object of type 'KinematicCollision3D'. what does it mean?

ORIGINAL:
Bit of a silly Question here, but I couldn’t find a way to do it, I’m making a bullet and I want to check what it collides with (obviously)

so my setup rn is:
CharacterBody3d
__CollsionShape3d
__MeshInstance3d

and my Script is

extends CharacterBody3D

var speed = 50
@onready var timer: Timer = $DespawnTimer

func _process(delta: float) -> void:
	position += transform.basis * Vector3(0,0,-speed) * delta

I want to add logic to check for the collider and let me access it (change exported Health variable)

You should use the built-in collision functions instead of modifying the position directly.

how do I make it move with move_and_slide()?
edit: nvm i found out

so My code is now

extends CharacterBody3D

func _physics_process(delta: float) -> void:
	# position += transform.basis * Vector3(0,0,-speed) * delta
	var speed = transform.basis * Vector3(0,0,-50) * delta
	self.velocity += speed
	
	for i in get_slide_collision_count():
		var collision = get_slide_collision(i)
		if collision.Health:
			collision.Health -= 1
	
	move_and_slide()

However I get Invalid access to property or key 'Health' on a base object of type 'KinematicCollision3D'. what does it mean?

The collision object only contains information about the collision itself. To get the real collider, use collision.get_collider().

1 Like

thanks, but I already fixed it with Area3Ds

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.