Hey, i'm new Goddot user
I have a problem with implementing the sound movement in the code, my sound $YSort/Walk.play(); its called on each frame. How to do it correctly ? sorry for my English
extends KinematicBody2D
export var max_jumpAmount = 0
export var max_jumpLeft = 1
var velocity = Vector2()
var onGround = true
const UP = Vector2(0, -1)
const Jump_Height = -300
const Gravity = 20
const Friction = 500
const Acceleration = 500
const Speed = 120
onready var animationPlayer = $AnimatedSprite
func _ready():
pass
func _physics_process(delta):
Movement()
func Movement():
velocity.y += Gravity
if Input.is_action_pressed("ui_right"):
velocity.x = Speed
animationPlayer.flip_h = false
animationPlayer.play("Run")
$YSort/Walk.play()
elif Input.is_action_pressed("ui_left"):
velocity.x = -Speed
animationPlayer.flip_h = true
animationPlayer.play("Run")
$YSort/Walk.play()
else:
animationPlayer.play("Idle")
$YSort/Walk.stop()
velocity.x = 0
if Input.is_action_just_pressed("ui_up"):
if max_jumpAmount < max_jumpLeft:
max_jumpAmount += 1
velocity.y = Jump_Height
$YSort/JumpSound.play()
onGround = false
if is_on_floor():
onGround = true
max_jumpAmount = 0
else:
onGround = false
if velocity.y < 0:
animationPlayer.play("Jump")
else:
animationPlayer.play("Fall")
velocity = move_and_slide(velocity, UP)