Hello, I’m trying to make a cinematic platformer in the style of the original Prince of Persia.
I was able to make the player climb up and onto a collision shape platform when pointing/jumping right along with jumping right while standing and running using a state machine.
The problem occurs when the player is trying to climb towards the left, he just bounces off the side.
Also when he jumps when facing left, the animation is correct, but the physics take him to the right as well.
I tried to include a variable for the direction facing (var Direction)
but its probably not working, is there any other way to distinguish what direction the player is facing?
@export
var walk_state: State @export
var idle_state: State @export
var climb_state : State @export
var jump_force: float = 600 @export var _speed = 250 #(pixels/sec). Climbing Speed @export var direction = Vector2.RIGHT
Please use , your code is too hard to read right now.
I think checking this line will solve your problem: var target = parent.position + Vector2(-2,10)
Hello, I’ve tried playing around with those values but no changes
Here’s the code for the climb state:
extends State
#climb
@export
var walk_state: State
@export
var idle_state: State
@export
var climb_state : State
@export
var jump_force: float = 600
@export var _speed = 150 #(pixels/sec). Climinb Speed - originally set to 500
@export var direction = Vector2.RIGHT
func enter() -> void:
super()
parent.animations.play("Climb")
parent.velocity.y = -jump_force
func process_physics(delta: float) -> State:
parent.velocity.y += gravity * delta
var _gravity = 1000
var _movement = Input.get_axis('left', 'right') * move_speed
parent.move_and_slide()
parent.apply_floor_snap()
if parent.is_on_wall_only():
if parent.is_on_wall_only() and Input.is_action_pressed("jumpup") and Vector2.RIGHT:
var target = parent.position + Vector2(2,-10)
parent.velocity.x = 4
parent.velocity.y = 10
parent.velocity = parent.position.direction_to(target) * _speed
elif parent.is_on_wall_only() and Input.is_action_pressed("jumpup") and Vector2.LEFT:
var target = parent.position + Vector2(-2,-10)
parent.velocity.x = -4
parent.velocity.y = 10
parent.velocity = parent.position.direction_to(target) * _speed
else: if parent.is_on_floor_only():
if parent.is_on_wall_only():
parent.animations.stop("Climb")
parent.velocity.x = 0
return idle_state
return null
This is for the jump up state which happens before climb:
extends State
#jumpup
@export
var fall_state: State
@export
var idle_state: State
@export
var walk_state: State
@export
var climb_state: State
@export var direction = Vector2.RIGHT
@export
var jump_force: float = 400 #jump height
func enter() -> void:
super()
parent.animations.play("JumpUp")
parent.velocity.y = -jump_force
func process_physics(delta: float) -> State:
parent.velocity.y += gravity * delta
var _gravity = 10
var movement = Input.get_axis('left', 'right') * move_speed
if movement != 0:
parent.animations.flip_h = movement < 0
parent.velocity.x = movement
parent.move_and_slide()
parent.apply_floor_snap()
if parent.is_on_floor():
if movement != 0:
return walk_state
return idle_state
if parent.is_on_wall_only():
return climb_state
return null