0 votes

I would like to define some classes of objects inheriting properties and methods to organize the objects and scripting of my game. For example:

Character - extends KinematicBody. Has health, can take damage and respond to healing

Player - extends Character. Can pickup objects and respond to user input

Enemy - extends Character. Has an AI-driven behaviour.

Trigger - has collision, activates other objects on contact with a Player node

Pickup - detects collisions with Players, grants them health or items

HealthPickup - extends Pickup - heals players on contact

WeaponPickup - extends Pickup - grants a selected weapon to a Player on contact

AmmoPickup - extends Pickup - grants ammo of selected type and amount to a Player on contact

And so on...

I guess Godot has great tools to do this, but currently I have no idea how to organize my code and objects using this "tree" logic.

I've been reading up on classes, duck typing etc, but I'm still completely oblivious to how I can make this work for my game.

in Engine by (199 points)

1 Answer

+2 votes

In Godot, you can use inheritance with both scripts and scenes.

See this tutorial for an example: http://kidscancode.org/blog/2018/01/godot3_inheritance/

by (20,677 points)

Thanks! I'm going through that, though the example in that article/video is pretty complex for the starters. I skip a lot of that, as I want to make myself the simplest implementation possible first, before going into deeper examples.

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.