Godot Version
4.3
Question
I am new to coding and gamedev and I dont know, why the hell, the function doesn’t get called. Its all there, but still it wont work.
Here the Code, where the Invalid Call Occurs on gravity_component.handle_gravity :
extends CharacterBody2D
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
@export_subgroup("Nodes")
@export var gravity_component: GravityComponent
@export var input_component: InputComponent
@export var movement_component: MovementComponent
@export var animation_component: AnimationComponent
@export var jump_component: JumpComponent
@export var punch_component: PunchComponent
func _physics_process (delta: float) -> void:
gravity_component.handle_gravity(self, delta)
movement_component.handle_horizontal_movement(self, input_component.input_horizontal)
animation_component.handle_move_animation(input_component.input_horizontal)
jump_component.handle_jump(self, input_component.get_jump_input())
animation_component.handle_jump_animation(jump_component.is_jumping, gravity_component.is_falling)
animation_component.handle_punch_animation(input_component.get_punch_input())
move_and_slide()
And here the Code for the GravityComponent:
class_name GravityComponent
extends Node
@export_subgroup("Settings")
@export var gravity: float = 1000.0
@export var is_falling: bool = false
func handle_gravity(body: CharacterBody2D, delta: float) -> void:
if not body.is_on_floor():
body.velocity.y += gravity * delta
is_falling = body.velocity.y > 0 and not body.is_on_floor()