The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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? :/

in Engine by (569 points)

1 Answer

0 votes
Best answer

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.

by (290 points)
selected by

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.

sure, I dont see why not :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.