How can I get around this inheritance problem?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HeroRobb
:warning: Old Version Published before Godot 3 was released.

I’m having an issue with collisions. Basically, I test to see if an enemy hit the player, and then do stuff accordingly. Like this

if (is_colliding() && get_collider() extends playerPreload):

The problem is that now that I’ve started implementing an attack the player can do, it’s crashing. I’ve made the attack have a separate hitbox that only monitors while the player is attacking. This works fine about 90% of the time, but if an enemy moves into the attacking hitbox after the player has begun to attack, the code above crashes with the error “Left operand of ‘extends’ is not an instance of anything.”

So, is there a way around this? I suppose I could turn the attack hitboxes into their own scene, but that doesn’t seem like the most efficient approach.

I guess you should just write get_collider() != null, but I’m not really sure…

Bojidar Marinov | 2016-03-17 09:52

:bust_in_silhouette: Reply From: Akien

I’m a bit puzzled by this issue and the Left operand of 'extends' is not an instance of anything.. Even if the CollisionObject does not extend a PackedScene, it’s still an instanced node per se, so the error message is weird (and IMO it should just return false instead of complaining).

A way around this issue in your case would be to use groups, e.g. “players” and “attacks”, so that you can use:

if is_colliding():
    if get_collider().is_in_group("players"):
        get_collider().take_damage(self.strength)
    elif get_collider().is_in_group("attacks"):
        self.take_damage(get_collider().strength)

That’s a good idea. Thank you. It works fine now and doesn’t complain any more.

HeroRobb | 2016-03-17 13:05