Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | İlker SARI |
When i click the button my kick-jump and punch just activate 1st frame of animated sprite. These are the pictures:
This one is is_action_just_pressed
and just show the first frame of the action
This one is is_action_pressed
and i have to stay pushed
extends KinematicBody2D
export var jump_count = 0
const MAX_JUMP_COUNT = 2
#!Sprint
const SPRINT_ACCELARATION = 175
const SPRINT_SPEED = 700
const MAX_SPEED = 350
const GRAVITY = 20
const JUMP = -600
const WALL_SLIDE = 100
const ACCELARATION = 50
var crouch_air = 50
var motion = Vector2()
const RESISTANCEGRAV = Vector2(0, -1)
func _physics_process(delta):
#!Falling Death
if motion.y > 1750: # change as needed
get_tree().reload_current_scene()
motion.y += GRAVITY
var friction = false
if Input.is_action_pressed("ui_right"):
motion.x += ACCELARATION
motion.x = min(motion.x, MAX_SPEED)
$plyr_sprite.flip_h = false
$plyr_sprite.play("Run")
if Input.is_action_pressed("ui_sprint"):
motion.x += SPRINT_ACCELARATION
motion.x = min(motion.x, SPRINT_SPEED)
elif Input.is_action_pressed("ui_left"):
motion.x -= ACCELARATION
motion.x = max(motion.x, -MAX_SPEED)
$plyr_sprite.flip_h = true
$plyr_sprite.play("Run")
if Input.is_action_pressed("ui_sprint"):
motion.x -= SPRINT_ACCELARATION
motion.x = max(motion.x, -SPRINT_SPEED)
# Punch and Kick on floor
elif Input.is_action_just_pressed("ui_punch"):
$plyr_sprite.play("Punch")
motion.x = 0
elif Input.is_action_just_pressed("ui_kick"):
$plyr_sprite.play("Kick")
motion.x = 0
else:
friction = true
$plyr_sprite.play("Idle")
if friction == true:
motion.x = lerp(motion.x, 0, 0.2)
if is_on_floor():
jump_count = 0
$plyr_hitbox.disabled = false
$plyr_hitbox_crouch.disabled = true
if Input.is_action_pressed("ui_down") && Input.is_action_pressed("ui_right"):
$plyr_sprite.play("Run")
elif Input.is_action_pressed("ui_down") && Input.is_action_pressed("ui_left"):
$plyr_sprite.play("Run")
elif Input.is_action_pressed("ui_down"):
$plyr_sprite.play("Crouch")
$plyr_hitbox.disabled = true
$plyr_hitbox_crouch.disabled = false
if Input.is_action_just_pressed("ui_up"):
if jump_count < 2:
motion.y = JUMP
jump_count += 1
if friction == true:
motion.x = lerp(motion.x, 0, 0.1)
else:
if jump_count < 2 && Input.is_action_just_pressed("ui_up"):
motion.y = JUMP
$plyr_sprite.play("Jump")
jump_count += 1
elif motion.y < 0 && !Input.is_action_pressed("ui_down"):
$plyr_sprite.play("Jump")
elif motion.y > 0 && !Input.is_action_pressed("ui_down"):
$plyr_sprite.play("Fall")
elif motion.y > 0 && Input.is_action_pressed("ui_down"):
$plyr_sprite.play("Crouch")
if friction == true:
motion.x = lerp(motion.x, 0, 0.05)
if is_on_wall():
jump_count = 1
#Wall Sliding Sprite with 1 picture
#$plyr_sprite.play("Punch")
if motion.y > 0:
motion.y = WALL_SLIDE
if Input.is_action_pressed("ui_right") and Input.is_action_just_pressed("ui_left"):
motion.y = JUMP * .8
if Input.is_action_pressed("ui_left") and Input.is_action_just_pressed("ui_right"):
motion.y = JUMP * .8
motion = move_and_slide(motion, RESISTANCEGRAV)
When i click the button my kick-jump and punch just activate 1st frame of animated sprite.
This one is is_action_pressed
and i have to stay pushed
This one is is_action_just_pressed
and just show the first frame of the action