Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | PopeRigby |
I have a slide maneuver setup that allows the player to quickly move in the direction they’re walking in. It also lowers their hitbox, but I haven’t implemented that yet. Here’s how all the movement looks in my player.gd:
const GRAVITY = 1300.0 # pixels/second/second
# Angle in degrees towards either side that the player can consider "floor"
const FLOOR_ANGLE_TOLERANCE = 50
const WALK_FORCE = 1600
const WALK_MIN_SPEED = 10
const WALK_MAX_SPEED = 400
const STOP_FORCE = 1500
const JUMP_SPEED = 600
const JUMP_MAX_AIRBORNE_TIME = 0.4
const SLIDE_SPEED = 600
const MAX_SLIDE_TIME = 0.4
var velocity = Vector2()
var rot_dir
var can_shoot = true
var health
var on_air_time = 100
var jumping = false
var can_slide = true
onready var oldScale = get_node("Sprite").get_scale()
onready var oldPosition = get_node("Sprite").get_position()
var prev_jump_pressed = false
func _ready():
health = start_health
emit_signal("health_changed", health)
func _physics_process(delta):
# Create forces
var force = Vector2(0, GRAVITY)
var move_left = Input.is_action_pressed("move_left")
var move_right = Input.is_action_pressed("move_right")
var jump = Input.is_action_pressed("jump")
var slide = Input.is_action_pressed("slide")
var stop = true
if move_left:
if velocity.x <= WALK_MIN_SPEED and velocity.x > -WALK_MAX_SPEED:
force.x -= WALK_FORCE
stop = false
elif move_right:
if velocity.x >= -WALK_MIN_SPEED and velocity.x < WALK_MAX_SPEED:
force.x += WALK_FORCE
stop = false
# slide right
if slide and move_right and can_slide:
can_slide = false
velocity.x = +SLIDE_SPEED
# slide left
elif slide and move_left and can_slide:
can_slide = false
velocity.x = -SLIDE_SPEED
if stop:
var vsign = sign(velocity.x)
var vlen = abs(velocity.x)
vlen -= STOP_FORCE * delta
if vlen < 0:
vlen = 0
velocity.x = vlen * vsign
# Integrate forces to velocity
velocity += force * delta
# Integrate velocity into motion and move
velocity = move_and_slide(velocity, Vector2(0, -1))
My current issue is, if the player holds down the slide key, they can keep sliding forever, which currently looks like they’re just walking at an accelerated pace. I want them to only be able to slide for about 0.4 seconds, and then they have to wait a second or two before they can slide again. How do I do this?