Added wall jumps and tweaked values and movement
This commit is contained in:
@@ -5,8 +5,10 @@ extends NodeState
|
||||
|
||||
const jumpGravity = player.GRAVITY
|
||||
|
||||
var dashSpeed: float = 500
|
||||
var dashTime: float = .3
|
||||
@onready var dashSpeed: float = player.dashSpeed
|
||||
@onready var jumpHight: float = player.jumpHight
|
||||
|
||||
var dashTime: float = .2
|
||||
var dashDone: bool = false
|
||||
var canDash: bool = true
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@ extends NodeState
|
||||
|
||||
|
||||
@export_category("Fall State")
|
||||
@export var coyoteTime: float = .2
|
||||
@export var coyoteTime: float = .4
|
||||
var coyoteJump: bool
|
||||
|
||||
const GRAVITY = player.GRAVITY
|
||||
@onready var speed = player.speed
|
||||
@onready var maxSpeed = player.maxSpeed
|
||||
@onready var maxSpeed = player.maxAirSpeed
|
||||
@onready var friction = player.airFriction
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ func on_phyisics_process(delta: float) -> void:
|
||||
|
||||
if direction:
|
||||
player.velocity.x += direction * speed * delta
|
||||
player.velocity.x = clamp(player.velocity.x, -maxSpeed, maxSpeed)
|
||||
player.velocity.x = move_toward(player.velocity.x, clamp(player.velocity.x, -maxSpeed, maxSpeed), friction * delta)
|
||||
|
||||
if direction != 0:
|
||||
animatedSprite2D.flip_h = false if direction > 0 else true
|
||||
|
||||
@@ -12,10 +12,13 @@ const jumpGravity = player.GRAVITY
|
||||
@onready var jumpHight = player.jumpHight
|
||||
@onready var maxJumpCount = player.maxJumpCount
|
||||
@onready var speed = player.speed
|
||||
@onready var maxSpeed = player.maxSpeed
|
||||
@onready var friction = player.friction
|
||||
@onready var maxSpeed = player.maxAirSpeed
|
||||
@onready var friction = player.airFriction
|
||||
@onready var wallPushBack = player.wallPushBack
|
||||
|
||||
var currentJumpCount: int = 0
|
||||
var wallJumpCoyoteTime: float = 0.3
|
||||
var canWallJump: bool = false
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func _physics_process(delta: float) -> void:
|
||||
@@ -28,6 +31,9 @@ func on_process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func on_phyisics_process(delta: float) -> void:
|
||||
|
||||
var direction: float = GameInputEvents.movement_input()
|
||||
|
||||
player.velocity.y += jumpGravity * delta
|
||||
if player.is_on_floor():
|
||||
currentJumpCount = 0
|
||||
@@ -35,7 +41,7 @@ func on_phyisics_process(delta: float) -> void:
|
||||
fallState.coyoteJump = false
|
||||
currentJumpCount += 1
|
||||
|
||||
if fallState.coyoteJump and currentJumpCount <= maxJumpCount:
|
||||
if fallState.coyoteJump and currentJumpCount < maxJumpCount:
|
||||
player.velocity.y = jumpHight
|
||||
fallState.coyoteJump = false
|
||||
currentJumpCount += 1
|
||||
@@ -43,12 +49,13 @@ func on_phyisics_process(delta: float) -> void:
|
||||
#multi jumps
|
||||
multiJump()
|
||||
|
||||
|
||||
#movment shit under here
|
||||
var direction: float = GameInputEvents.movement_input()
|
||||
|
||||
|
||||
if direction:
|
||||
player.velocity.x += direction * speed * delta
|
||||
player.velocity.x = clamp(player.velocity.x, -maxSpeed, maxSpeed)
|
||||
player.velocity.x = move_toward(player.velocity.x, clamp(player.velocity.x, -maxSpeed, maxSpeed), friction * delta)
|
||||
|
||||
if direction != 0:
|
||||
animatedSprite2D.flip_h = false if direction > 0 else true
|
||||
@@ -63,7 +70,7 @@ func on_phyisics_process(delta: float) -> void:
|
||||
func enter() -> void:
|
||||
ledgeGrabBox.disabled = false
|
||||
animatedSprite2D.play("Jump")
|
||||
if not fallState.coyoteJump:
|
||||
if not fallState.coyoteJump and not player.is_on_wall():
|
||||
currentJumpCount += 1
|
||||
multiJump()
|
||||
|
||||
@@ -91,6 +98,28 @@ func transition_states() -> void:
|
||||
|
||||
|
||||
func multiJump():
|
||||
if !player.is_on_floor() and currentJumpCount <= maxJumpCount and Input.is_action_just_pressed("move_jump"):
|
||||
if !player.is_on_floor() and currentJumpCount < maxJumpCount and Input.is_action_just_pressed("move_jump") and not player.is_on_wall() and not fallState.coyoteJump:
|
||||
player.velocity.y = jumpHight
|
||||
currentJumpCount += 1
|
||||
|
||||
if player.is_on_wall():
|
||||
canWallJump = true
|
||||
wallJumpCoyote()
|
||||
|
||||
if Input.is_action_just_pressed("move_jump") and canWallJump:
|
||||
var boost = 150
|
||||
print("wall jump")
|
||||
player.velocity.y = jumpHight
|
||||
var wallDirection = player.get_wall_normal().x
|
||||
var direction: float = GameInputEvents.movement_input()
|
||||
if direction == wallDirection:
|
||||
print("boost")
|
||||
player.velocity.x =+ (wallPushBack + boost) * wallDirection
|
||||
else:
|
||||
print("no boost")
|
||||
player.velocity.x =+ wallPushBack * wallDirection
|
||||
currentJumpCount = 0
|
||||
|
||||
func wallJumpCoyote():
|
||||
await get_tree().create_timer(wallJumpCoyoteTime).timeout
|
||||
canWallJump = false
|
||||
|
||||
@@ -6,6 +6,7 @@ extends NodeState
|
||||
const GRAVITY = player.GRAVITY
|
||||
@onready var speed = player.speed
|
||||
@onready var maxSpeed = player.maxSpeed
|
||||
@onready var friction = player.friction
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func on_process(delta: float) -> void:
|
||||
@@ -16,8 +17,8 @@ func on_phyisics_process(delta: float) -> void:
|
||||
|
||||
if direction:
|
||||
player.velocity.x += direction * speed * delta
|
||||
player.velocity.x = clamp(player.velocity.x, -maxSpeed, maxSpeed)
|
||||
#player.velocity.x = move_toward(player.velocity.x, maxSpeed, 100 * delta)
|
||||
#player.velocity.x = clamp(player.velocity.x, -maxSpeed, maxSpeed)
|
||||
player.velocity.x = move_toward(player.velocity.x, clamp(player.velocity.x, -maxSpeed, maxSpeed), friction * delta)
|
||||
|
||||
if direction != 0:
|
||||
animatedSprite2D.flip_h = false if direction > 0 else true
|
||||
|
||||
Reference in New Issue
Block a user