Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- var velocity = Vector3()
- var speed = 5
- export (int) var damage := 10
- var AttackPoints = 3
- var is_Attacking = true
- onready var anim_player = $AnimatedSprite3D
- enum State {
- IDLE
- MOVING
- ATTACKING
- }
- var state = State.IDLE
- func _ready():
- $attackArea/CollisionShape.disabled = true
- func _physics_process(delta):
- velocity = Vector3()
- if Input.is_action_pressed("ui_right"):
- velocity.x += 1
- if Input.is_action_pressed("ui_left"):
- velocity.x -= 1
- if Input.is_action_pressed("ui_up"):
- velocity.z -= 1
- if Input.is_action_pressed("ui_down"):
- velocity.z += 1
- if velocity.length() > 0:
- velocity = velocity.normalized() * speed
- move_and_slide(velocity)
- state = State.MOVING
- else:
- state = State.IDLE
- if Input.is_action_pressed("attack"):
- state = State.ATTACKING
- update_state()
- func update_state():
- if state == State.IDLE:
- anim_player.play("idle")
- elif state == State.MOVING:
- anim_player.play("walking")
- elif state == State.ATTACKING:
- if is_Attacking:
- $attackArea/CollisionShape.disabled = true
- if Input.is_action_just_pressed("attack") && AttackPoints == 3:
- $AttackResetTimer.start()
- $AnimatedSprite3D.play("Attack_1")
- AttackPoints = AttackPoints - 1
- $attackArea/CollisionShape.disabled = false
- elif Input.is_action_just_pressed("attack") && AttackPoints == 2:
- $AttackResetTimer.start()
- $AnimatedSprite3D.play("Attack_2")
- AttackPoints = AttackPoints - 1
- $attackArea/CollisionShape.disabled = false
- elif Input.is_action_just_pressed("attack") && AttackPoints == 1:
- $AttackResetTimer.start()
- $AnimatedSprite3D.play("Attack_3")
- AttackPoints = AttackPoints - 1
- $attackArea/CollisionShape.disabled = false
- func _on_AttackResetTimer_timeout():
- AttackPoints = 3
- func _on_attackArea_body_entered(body):
- if body.has_method("knockback"):
- body.knockback(damage)
- func _on_AnimatedSprite3D_animation_finished():
- if $AnimatedSprite3D.animation == "Attack_1":
- $AnimatedSprite3D.play("idle")
- elif $AnimatedSprite3D.animation == "Attack_2":
- $AnimatedSprite3D.play("idle")
- elif $AnimatedSprite3D.animation == "Attack_3":
- $AnimatedSprite3D.play("idle")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement