0 votes

For a side scroller game i need variuous scene ( main , player , weapon, enemy ).
In the script of the main one, I instance them with "add_child" and they spawn correctly on the screen with their variables.
Now i want to add collision to player, bullet and enemy that are all RigidBody2D with their CollisionShape2D.

This is the code for the Enemy

extends RigidBody2D

var life = 250

func _ready():
    get_node("Timer").start()
    pass
func _on_weapon_body_entered(body):
    if body.is_in_group("weapon"):
        life=life-body.damage
    else:
        life=life+1
    pass


func _on_Timer_timeout():
    get_node("Label").text=String(life)
    get_node("Timer").start()
    pass

In the weapon scene there is a group called weapon

What is the problem?

in Engine by (51 points)

1 Answer

0 votes

First thing first, is the onweaponbodyentered() connected to anything? Maybe share the project so we get some context?

by (1,003 points)

Is connected to the father RigidBody2D (so the enemy)

Here's the project:
https://mega.nz/#!e1kG0ArB!q_SdQuB4QpMXhiCLYhL3AKsYecIiy35QBbNaNkBtqVs

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.