Handling collosions between different scenes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DodoIta
:warning: Old Version Published before Godot 3 was released.

I have a shield and an enemy who shoots bullets towards the shield and both shield and bullets are KinematicBody2D-type located in separated scenes.
I want the bullet to be deflected once it hits the shield but I don’t know how to do that since it belongs to a different scene.
I tried something like this in the shield’s scene but it doesn’t seem to work:

func _fixed_process(delta):
    if(is_colliding()):
	    var entity = get_collider()
	    var normal = get_collision_normal()
	    entity.move(normal * entity.speed * delta)

What’s wrong here? :confused:

:bust_in_silhouette: Reply From: Nuno Donato

The move will only be executed when the bullet hits the shield, means that in the next frame, it is not colliding anymore, so it wont move again.

I didn’t think about that, thanks!
Since the shield is in a different scene, would it work if I write a function deflect inside the bullet scene and call it inside the shield script like this?

 if(is_colliding()):
    var entity = get_collider()
    var normal = get_collision_normal()
    entity.deflect(normal)

or would it give me an error? The code is just an example, I’m interested in Godot’s operation between scenes.

DodoIta | 2017-03-27 14:25

sure, I dont see why not :slight_smile:

Nuno Donato | 2017-03-27 14:26