0 votes

Can't understand what is happening. One of the kits can't be picked up. Tried to look up through web but couldn't find any solution. If one is spawned it can't be picked. If spawned few the first one that player has collided with.

I have this in my enemy script:

func kill():
dead = true

if random.randi_range(1,50) == 42:
    var zomb_pos = self.translation
    zomb_pos.y = zomb_pos.y - 0.5

    var HPKit = HPkit.instance()
    get_tree().call_group("powerups", "set_player", self)


$CollisionShape.disabled = true

and this in my HP kit:

func __physics__process(delta):

var coll = raycast.get_collider()

if player == null:
if dead:

var vec_to_plr = player.translation - translation
vec_to_plr = vec_to_plr.normalized()
raycast.cast_to = vec_to_plr * 1.1

if raycast.is_colliding() and coll != null and coll.name == "Player":
    print("colliding with HPKit")
    if coll.health <= 99:
        coll.health += 10

Any help? I just can not understand what am I doing wrong. Godot doesn't show any error.

Godot version 3.2.3
in Engine by (19 points)

Solved it with the help of a good guy

1 Answer

0 votes
Best answer

Solved it by removing raycast from HPKit and making it Area object instead of a Kinematic body. Then added signal that was listening for entering bodies.

Enemy code that spawned kits changed too:

var zomb_pos = self.translation
zomb_pos.y = zomb_pos.y - 0.5
zomb_pos.x = zomb_pos.x + 0.5

var HPKit = HPkit.instance()

by (19 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 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 webmaster@godotengine.org with your username.