This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

So basically the collisions are kinda f*cked for some reason and don't work half the time and as far as I could see the only pattern is that the first couple bullets always worked and after that it was(as far as i could see more up to chance) random but it did work more often when you moved up and down. I have tried removing, code double checked everything asked on discord and nothing worked. I think its not associated with the script but something else(maybe even an engine bug) I uploaded the project to MegaUp. THE LINK: https://megaup.net/Vxip/Space_shooter.rar. But in case its just a matter with the code and I am stupid here it is:
THE BULLET:

extends KinematicBody2D

export var speed = 0.0

func _physics_process(delta):
    move_and_slide(Vector2(speed, 0))
    for i in get_slide_count():
        var collision = get_slide_collision(i)
        if collision.collider.get_collision_layer_bit(2):
            collision.collider.queue_free()
            queue_free()



func _on_bomb_timeout():
    queue_free()

THE ENEMY:

extends KinematicBody2D

export var HP = 0


func _process(delta):
    move_and_slide(Vector2.ZERO)
    for i in get_slide_count():
        var collision = get_slide_collision(i)
        HP -= 1
        collision.collider.queue_free()
        if HP <= 0:
            queue_free()
Godot version 3.2.3
in Engine by (26 points)

Maybe it has to do with the callback functions that are being used? The bullet script uses _physics_process() while the enemy script uses _process(). Since collision detection is calculated in the _physics_process() function, change the callback function in the enemy script to _physics_process().

Sadly it didnt work. But I doubt this would do anything since they are not associated.

I'm not sure I'm understanding your question, but it seems like you need to enable continuous collision detection. This enabled more precise collisions at the cost of a bit of performance.

1 Answer

0 votes

When two things move to touch one another, you do not know which one will detect the collision.

For instance, say you have two moving entities aligned and going in the same direction, but the front one is slower. Every time the back one moves, it collides with the front one, but when the front one moves, it stops colliding:

Initial:

A-->       B->

A Moves and collides with B:

       A-->B->

B moves without colliding with A:

       A-->   B->

To avoid that, you can make each moving Nodes implement a function, say on_collision(collision, with), and whenever one collides, they call their own function, and then the one of whoever they collided with:

for i in get_slide_count():
    var collision = get_slide_collision(i)
    on_collision(collision, collision.collider)
    if collision.collider.has_method(on_collision):
         collision.collider.on_collision(collision, self)

Physics related functions like move_and_... should always be called inside a _physics_process() or a function called inside one.

by (2,720 points)
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.