please somone help me im struggle with this one, when i pressed fire while im not moving is just stop the animation, but when i jump and while on the air i pressed fire the attack animation, help me :(
heres my code:
extends KinematicBody
const MOVE_SPEED = 10
const JUMP_FORCE = 25
const GRAVITY = 0.98
const MAX_FALL_SPEED = 25
const H_LOOK_SENS = 0.4
onready var cam = $CamBase
onready var anim = $main/AnimationPlayer
var y_velo = 0
func _process(delta):
anim.get_animation("Run").set_loop(true)
if Input.is_action_pressed("quit"):
get_tree().quit()
if Input.is_action_pressed("restart"):
kill()
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
rotation_degrees.y -= event.relative.x * H_LOOK_SENS
func _physics_process(delta):
var move_vec = Vector3()
if Input.is_action_pressed("fire"):
anim.play("Attack")
if Input.is_action_pressed("forward"):
move_vec.x -= 1
if Input.is_action_pressed("backward"):
move_vec.x += 1
if Input.is_action_pressed("right"):
move_vec.z -= 1
if Input.is_action_pressed("left"):
move_vec.z += 1
move_vec = move_vec.normalized()
move_vec = move_vec.rotated(Vector3(0, 1, 0), rotation.y)
move_vec *= MOVE_SPEED
move_vec.y = y_velo
move_and_slide(move_vec, Vector3(0, 1, 0))
var grounded = is_on_floor()
y_velo -= GRAVITY
var just_jumped = false
if grounded and Input.is_action_just_pressed("jump"):
just_jumped = true
y_velo = JUMP_FORCE
if grounded and y_velo <= 0:
y_velo = -0.1
if y_velo < -MAX_FALL_SPEED:
y_velo = -MAX_FALL_SPEED
if just_jumped:
play_anim("Jump")
elif grounded:
if move_vec.x == 0 and move_vec.z == 0:
play_anim("Idle")
func play_anim(name):
if anim.current_animation == name:
return
anim.play(name)
func kill():
get_tree().reload_current_scene()