`I followed my first tutorial on making a simple Plattformer.
Now i have a slime enemy (Node2D) that floats and moves while doing so.
I would like for it to have gravity and be able to move on ramps for example a bride with a slight curve down and up again.
my Player (CharacterBody2D) can do so but i cant use the same fuctions on my slime because “_physics_process” is not a thing in Node2D as it seems.
must i change my Node2D in a CharacterBody2D for it to work or is there another way (because i use a killZone on enemys that i think cant user on a CharacterBody2D).
Additional General Question:
How can i combine Scripts so lets say i have some basic movements or HP and want multiple enemys to inherate it from lets say a abstract enemy how can i do that in Godot
I’m not sure why you think this. _physics_process is defined in Node, and Node2D inherits from Node. So Node2D definitely does have a (virtual, override-able) method like that.
It’s probably more fruitful to use composition over inheritance. Make a new scene with a Node root node. Rename the root node to HealthComponent. Add this script to HealthComponent (or similar):
class_name HealthComponent extends Node
signal ko
@export var max_hitpoints : int = 10
@export var current_hitpoints : int = max_hitpoints
func change_health(amount : int)->void:
current_hitpoints -= amount
if current_hitpoints > max_hitpoints:
current_hitpoints = max_hitpoints
elif current_hitpoints < 0:
current_hitpoints = 0
if current_hitpoints == 0:
ko.emit()
Save the scene. Now add the scene as an instance to anything you want to have health and be able to die.
CharacterBody2D does not respond to physics; it’s a class intended to be used by anything a player has direct control over. Personally, I’d try to implement the enemies as RigidBody2Ds. That node does not have the is_on_floor method, but does respond to gravity.