Godot Version
4.3
Question
Given one script that extends a general node such as just “Node” how can I extend that script in another script while using a more specific node that inherits from that base node such as “CharacterBody2D”.
Example:
damage.gd - a script to handle simple health and damaging for any node type:
extends Node
class_name Damage
const STARTING_HEALTH = 100
var health : int
func _ready():
reset_health()
func reset_health():
health = STARTING_HEALTH
func damage(dmgValue : float):
health -= dmgValue
character_controller.gd - a character controller that also needs health:
extends Damage
const MOVEMENT_SPEED = 125
func _physics_process(delta):
var movementVector = Vector2(Input.get_axis("move_left", "move_right"), Input.get_axis("move_up", "move_down"))
self.velocity = movementVector * MOVEMENT_SPEED
move_and_slide()
[Hopefully these scripts make sense as I cut them down for posting to just necessary parts to make easier to read]
The problem here is that move_and_slide() is in CharacterBody2D but not in Node so the code won’t run. I assume there is some syntax that makes a script that inherits another also inherit a more specific node from the original script?