Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- onready var AnimSprite = $AnimatedSprite3D
- var velocity = Vector3(0, 0, 0)
- var speed = 70
- var isAttacking = false
- var isJumping = false
- var gravity = -20
- var jump_impulse = 300
- var input_vector = Vector3.ZERO
- onready var AttackArea = $AttackArea
- export (int) var damage := 10
- var canMove = false
- var timer = null
- var crouch_delay = 0.5
- var isCrouch = true
- var current_animation
- func _ready():
- timer = Timer.new()
- timer.set_one_shot(true)
- timer.set_wait_time(crouch_delay)
- timer.connect("timeout", self, "on_timeout_complete")
- add_child(timer)
- func on_timeout_complete():
- isCrouch = true
- func _process(delta):
- if $AnimatedSprite3D.animation == "punch" and $AnimatedSprite3D.frame !=2:
- return
- apply_gravity()
- if is_on_floor():
- input_vector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
- input_vector.z = Input.get_action_strength("move_up") - Input.get_action_strength("move_down")
- input_vector = input_vector.normalized()
- if input_vector != Vector3.ZERO and not canMove:
- velocity.x = input_vector.x * speed
- velocity.z = input_vector.z * -speed
- AnimSprite.play("walk")
- else:
- velocity.x = 0
- velocity.z = 0
- AnimSprite.play("idle")
- isAttacking = false
- if Input.is_action_just_pressed("punch") and not isAttacking: #and isWalking:
- $AnimatedSprite3D.play("punch")
- $AttackArea/CollisionShape.disabled = false
- canMove = true
- if Input.is_action_just_pressed("reverse_kick"):
- velocity.x = 0
- velocity.z = 0
- $AnimatedSprite3D.play("reverse_kick")
- isAttacking = true
- else:
- if not is_on_floor():
- velocity.y -= gravity * delta
- velocity.z = 0
- isAttacking = false
- if Input.is_action_just_pressed("jump") && isCrouch:
- velocity.y = 0
- AnimSprite.play("crouch")
- isCrouch = false
- timer.start()
- if velocity.x > 0:
- AnimSprite.flip_h = false
- scale.x = 29
- elif velocity.x < 0:
- AnimSprite.flip_h = false
- scale.x = -29
- velocity = move_and_slide(velocity, Vector3.UP)
- return velocity.normalized()
- func apply_gravity():
- velocity.y = velocity.y + gravity
- func _on_AnimatedSprite3D_animation_finished():
- if $AnimatedSprite3D.animation == "punch":
- $AttackArea/CollisionShape.disabled = true
- isAttacking = false
- if $AnimatedSprite3D.animation == "reverse_kick":
- $AttackArea/CollisionShape.disabled = true
- isAttacking = false
Add Comment
Please, Sign In to add comment