Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | prodtmk |
All of my “is pressed” codes work just fine but none of the “is just pressed” codes work. What am i doing wrong? I’m making a 2D platformer
Heres my player code:
extends KinematicBody2D
const UP = Vector2(0, -1)
const GRAVITY = 15
const ACCELERATION = 23
const MAX_SPEED = 125
const JUMP_HEIGHT = -300
var collision_info = move_and_collide(Vector2(0,0))
var motion = Vector2()
func _physics_process(delta):
motion.y += GRAVITY
var friction = false
if Input.is_action_pressed("ui_right"):
motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
$Sprite.flip_h = false
$AnimationPlayer.play("Run")
elif Input.is_action_pressed("ui_left"):
$Sprite.flip_h = true
$AnimationPlayer.play("Run")
motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
else:
$AnimationPlayer.play("Idle")
friction = true
if is_on_floor():
if Input.is_action_just_pressed("ui_up"):
motion.y = JUMP_HEIGHT
if friction == true:
motion.x = lerp(motion.x, 0, 0.18)
else:
if motion.y < 0:
$AnimationPlayer.play("Jump")
if friction == true:
motion.x = lerp(motion.x, 0, 0.05)
if Input.is_action_just_pressed("ui_attack"):
$AnimationPlayer.is_playing("Attack")
motion = move_and_slide(motion, UP)