This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

As a learning exercise, I am trying to recreate "Asteroids". I've managed to get to the point with a moving ship, that fires bullets, at ever decreasing sizes of 'roids. Large, Medium and Small. Large when hit, splits into 2 new instances of med; med when hit splits into 2 new instances of small; and small when hit is the end of the chain.
I notice the code for each asteroid is very similar, so I would like some help building a parent class for the general asteroid. The problem is that I'm not sure what, and what not to include in the parent.

Each asteroid is an Area2D with coll2D, Timer, Sprite, and a Particle emitter.

I'll leave it there for now and expand with code if anyone can help.

Thanks :)

in Engine by (24 points)

How are these asteroids different? Is it only the size that differs? If so, you could create a conditional statement that checks the size of the asteroid and act accordingly.

1 Answer

+2 votes

I assume you are writing your project in GDScript. If you want to create a class that inherits some other class, use the

extends [name of the other class]

keyword. For example, if you have an Asteroid node, create a new node and put this in it :

extends Asteroid

Then, redefine the functions that you want to override there.

After a quick google search, I found this : https://kidscancode.org/blog/2018/01/godot3_inheritance/

by (83 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 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.