Advertisement
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
- onready var AttackArea = $AttackArea
- export (int) var damage := 10
- func _process(delta):
- _is_on_floor()
- apply_gravity()
- if is_on_floor() and not isAttacking:
- velocity.x = speed * Input.get_axis("move_left", "move_right")
- velocity.z = speed * Input.get_axis("move_up", "move_down")
- AnimSprite.play("walk")
- if velocity.x == 0 and velocity.z == 0:
- AnimSprite.play("idle")
- isAttacking == false
- if Input.is_action_just_pressed("punch"):
- velocity.x = 0
- velocity.z = 0
- $AnimatedSprite3D.play("punch")
- $AttackArea/CollisionShape.disabled = false
- isAttacking = true
- elif 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
- # if Input.is_action_pressed("ui_right"):
- velocity.z = 0
- isAttacking = false
- if velocity.x > 0:
- AnimSprite.flip_h = false
- scale.x = 29
- elif velocity.x < 0:
- AnimSprite.flip_h = false
- scale.x = -29
- func _is_on_floor():
- if Input.is_action_just_pressed("jump") and is_on_floor():
- velocity.y = jump_impulse
- AnimSprite.play("jumping")
- isAttacking = false
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement