Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- onready var animatedSprite = $AnimatedSprite3D
- var isAttacking = false
- var movement = Vector3(0, 0, 0)
- var speed = 150
- export (int) var damage := 10
- func _process(delta):
- var input_vector = Vector3.ZERO
- input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
- input_vector.z = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
- input_vector = input_vector.normalized()
- if input_vector != Vector3.ZERO:
- movement.x = input_vector.x * speed
- movement.z = input_vector.z * -speed
- $AnimatedSprite3D.play("walk")
- isAttacking = false
- else:
- if $AnimatedSprite3D.animation == "punch" and $AnimatedSprite3D.frame !=2:
- pass
- else:
- movement.x = 0
- movement.z = 0
- $AnimatedSprite3D.play("idle")
- isAttacking == false
- $attackArea/CollisionShape.disabled = true
- if Input.is_action_just_pressed("attack"):
- $AnimatedSprite3D.play("punch")
- $attackArea/CollisionShape.disabled = false
- isAttacking = true
- if movement.x > 0:
- animatedSprite.flip_h = false
- scale.x = 1
- elif movement.x < 0:
- animatedSprite.flip_h = false
- scale.x = -1
- movement = move_and_slide(movement * delta)
- #func _on_AnimatedSprite3D_animation_finished():
- # if $AnimatedSprite3D.play("punch"):
- # isAttacking = false
- func _on_attackArea_body_entered(body):
- if body.has_method("handle_hit"):
- body.handle_hit(damage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement