#Two KinematicBody2D don't collide when they are traveling in the same direction

10 messages · Page 1 of 1 (latest)

gaunt vine
#

I have a spaceship Node and a fireball Node.
in example 1, I don't move, the collision succeeds and the fireball gets deleted.
in example 2, I move towards the fireball, the collision succeeds and the fireball gets deleted.
in example 3, I move in the same direction as the fireball (the spaceship is faster than the fireball), the collision happen only on the fireball side.

#

Fireball code:

extends Node2D

export var velocity = Vector2(0,0.2)
var damage = 1


func _ready():
    if(randi() % 2 == 1):
    velocity.y *= (randi() % 5 + 10)

func _physics_process(_delta):
    var col = $KinematicBody2D.move_and_collide(velocity)
    if(col):
        if(col.collider.get_parent().has_method("hit")):
            col.collider.get_parent().hit(damage)
            self.queue_free()
#

Something that fixes this issue is adding collision code to the spaceship that does the same function

#

but I don't want to have duplicate code

#

so fireball isn't returning a collider but spaceship is

pseudo estuary
#

i'd suggest just making the projectile an Area2D and using either get_overlapping_bodies(), or using the body_entered signal to see if it's colliding with the player

gaunt vine
#

Okay thanks will try that

#

what type is body that body_entered gives?

#

it's returns the node?

#

Okay thanks it worked