Godot Version
4.4
Question
trying something on code on a different character node
i added sprite2d and collision shape to it, and code to but i used same gravity and move code of other character, well issue is i dont know why it doesnt move or why gravity doesnt work it feels like its a static body
( Gravity and speed Code is in _physics_process(delta: float))
extends CharacterBody2D
enum States {IDLE, WALKING, RUNNING, FLYING, FLYFORWARD, INTERACTING, TALKING}
# This variable keeps track of the character's current state.
var current_state: States = States.IDLE
var states: Dictionary = {
States.IDLE: _idle_state,
States.WALKING: _walk_state,
States.RUNNING: _run_state,
States.FLYING: _fly_state,
States.FLYFORWARD: _flyf_state,
States.INTERACTING: _interact_state,
States.TALKING: _talk_state,
}
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
func _idle_state():
print("Idle")
pass
func _walk_state():
print("Move")
pass
func _run_state():
print("run")
pass
func _fly_state():
print("fly")
pass
func _flyf_state():
print("FlyingForward")
pass
func _interact_state():
print("Touched that")
pass
func _talk_state():
print("Talking")
func _ready():
states[States.IDLE].call()
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity += get_gravity() * delta
states[current_state].call()
var speed = Input.get_axis("Walk Left", "Walk Right")
velocity.x = speed * SPEED
if speed > 0 or speed < 0:
is_on_floor()
current_state = States.WALKING
elif not is_on_floor():
current_state = States.FLYFORWARD
elif speed == 0:
not is_on_floor()
current_state = States.FLYING
else:
current_state = States.IDLE