Help Please urgent

Godot Version

4.4.1

Question

` how to make Player ( Character body 2d ) and Enemy ( Character body 2d ) collide well with each other and make player die after collision ?

extends CharacterBody2D
@onready var target = $“../Player” #refrence of Player Character Body 2D
var speed = 400

func _physics_process(delta):
var direction=(target.position-position).normalized()
velocity=direction * speed
look_at(target.position)
move_and_slide()’

If you need to delete the player, you can use a queue_free() function

If you need to see which bodies CharacterBody2D have collided with, you can useget_slide_collision_count with get_slide_collision

Sorry I want to show the player dead or simply take the game as touch and die ( similarly like those minecraft touch challanges )

I simply wants to add something that is like

if Player collides with Enemy Change scene to Game Over I only want this help I am new to the engine

Well, instead of completely deleting the player, you can temporarly disable the CharacterBody2D and then do animations/other stuff in your children.

When they die, You can set player’s CharacterBody2D disable_mode to DISABLE_MODE_REMOVE and process_mode to PROCESS_MODE_DISABLED, that way the character’s _process functions will no longer be processed and their physical collision not be used.

To still make sure your children are being processed, you can set their process_mode to PROCESS_MODE_PAUSABLE

You can send out death signal to children if you need to send them an event

Oh, if you wanna simply change the scene you can use load it from file or from PackagedScene

I recommend you follow the official 2D Tutorial. These are all basic skills. The tutorial will teach you how to do everything you asked about and teach you how to use the engine.

1 Like

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