My main issue is this code causes the character to slide up the wall, apparently ignoring wallslide
. I'm sure this is an error on my part as I'm very new to godot, any help would be appreciated.
extends KinematicBody2D
#=====================================
#variables and setup
#=====================================
export (int) var speed = 500
export (int) var jump_speed = -1400
export (int) var gravity = 4000
export (int) var wallslide = 100
var velocity = Vector2.ZERO
var gravitytrue = true
var state = MOVE
#=====================================
#state machine setup
#=====================================
enum {
MOVE,
ATTACK,
AIR,
WALL
}
func _ready():
print_debug("player enters")
func get_input():
#map full movement, add checks to make active in states
velocity.x = 0
if Input.is_action_pressed("ui_right"):
velocity.x += speed
print_debug("pressed right")
if Input.is_action_pressed("ui_left"):
velocity.x -= speed
print_debug("pressed left")
func _physics_process(delta):
#state machine handler, add new states in setup and define functions
match state:
MOVE:
move_state(delta)
ATTACK:
attack_state(delta)
AIR:
air_state(delta)
WALL:
wall_state(delta)
#=====================================
#state logic, remember to hand off state to each other
#=====================================
func move_state(delta):
get_input()
var snap = Vector2.DOWN * 16 if is_on_floor() else Vector2.ZERO
if gravitytrue:
velocity.y += gravity * delta
velocity = move_and_slide_with_snap(velocity, snap, Vector2.UP)
#Jump Mechanic
if Input.is_action_just_pressed("ui_accept"):
print_debug("jump pressed")
if is_on_floor():
velocity.y = jump_speed
print_debug("jump worked")
if is_on_wall():
state= WALL
func attack_state(delta):
pass
func air_state(delta):
pass
func wall_state(delta):
if velocity.y > 0:
velocity.y = 0
velocity = move_and_slide(Vector2.UP)
gravitytrue = false
if is_on_wall():
velocity.y += wallslide * delta
print_debug("is on wall")
#wall jump mechanic, needs to check where wall is and jump away, possibly add input
if Input.is_action_just_pressed("ui_accept"):
print_debug("wall jump pressed")
velocity.y = jump_speed
print_debug("jump worked")
if !is_on_wall():
state= MOVE