How to make this work : get_slide_collision() !

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

Hello,

for now I’d like just to kill my Player when he hits something. Basic right ?

I started with :
if get_slide_collision(0).collider_id == 1028: move_local_y(-80)

But it doesn’t work, but if I try this :
if get_slide_collision(0): if get_slide_collision(0).collider_id == 1028: move_local_y(-80)

It works ! But with bug says my console :confused:

I’m sure there is a better and simply way

Thanks a lot

:bust_in_silhouette: Reply From: gcivico

Hi.

Please try this way:

var collisionCounter = get_slide_count() - 1
if collisionCounter > -1:
    var col = get_slide_collision(collisionCounter)
    if col.collider_id == 1028:
        # do something ... 

It’s alive !!!

It was my understanding of the docs, I’ve to train that.

Edit : it only work once :confused:
After my character is killed, I do an get_tree().reload_current_scene() in the character’s script, and when I want to collide again, it doesn’t work :confused:

Thanks a lot !

mister_why | 2018-03-01 04:17

Hi.

That is rare… to kill my character I use myCharacterInScene.queue_free()then I can call get_tree().reload_current_scene() without poblems.

For example, my game scene use a tilemap. In the tilemap scene I have a Area2D with a script and a signal call body_entered. When the character (the character is another scene) enter that area, I call queue_free() and immediately get_tree().reload_current_scene() in the body_entered signal.

Maybe you have some code that you want to take in account when the scene load.

gcivico | 2018-03-01 16:26

Ah !

I was just doing : queue_free() !

How do you get the path of your character ? It’s also an other scene for me.

My tree right now it’s like : World
Player
TileMap
Path2D
StaticBody2D

Thx again

mister_why | 2018-03-01 17:07

This is what you want How to get node from another scene

gcivico | 2018-03-02 03:09

Ha ok !
I didn’t put that in a variable, why do I have to do that ?
Thanks again, I hope I’ll help you like wise :wink:

mister_why | 2018-03-02 19:38