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 SpeedStop = 0
- var isAttacking = false
- var isJumping = false
- var gravity = -10
- var jump_impulse = 200
- var canPick = true
- onready var AttackArea = $AttackArea
- export (int) var damage := 10
- func _process(delta):
- $"../Camera".global_transform.origin.x = global_transform.origin.x
- _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("walk2")
- if velocity.x == 0 and velocity.z == 0:
- AnimSprite.play("idle")
- isAttacking == false
- if Input.is_action_just_pressed("punch"):
- $snapPunch.play()
- velocity.x = 0
- velocity.z = 0
- speed = 0
- $AnimatedSprite3D.play("punch")
- $AnimatedSprite3D/AttackArea/CollisionPunch.disabled = false
- isAttacking = true
- elif isAttacking == false:
- speed = 70
- # elif Input.is_action_just_pressed("crouch"):
- # velocity.x = 0
- # velocity.z = 0
- # $AnimatedSprite3D.play("crouching")
- # isJumping = false
- if Input.is_action_just_pressed("reverse_kick"):
- $snapPunch.play()
- velocity.x = 0
- velocity.z = 0
- $AnimatedSprite3D.play("reverse_kick")
- $AnimatedSprite3D/AttackArea/CollisionRearKick.disabled = false
- 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.scale.x = 1
- elif velocity.x < 0:
- AnimSprite.scale.x = -1
- func _is_on_floor():
- if Input.is_action_just_pressed("PickUp"):
- $AnimatedSprite3D.play("pick_up")
- velocity.x = 0
- velocity.z = 0
- isAttacking = true
- if Input.is_action_just_pressed("jump") and is_on_floor():
- velocity.y = jump_impulse
- AnimSprite.play("jumping")
- $snapPunch.play()
- $AnimatedSprite3D/AttackArea/CollisionAirPunch.disabled = true
- isAttacking = false
- elif Input.is_action_just_pressed("airAttack") and not is_on_floor():
- $AnimatedSprite3D.play("air_attack")
- $snapPunch.play()
- $AnimatedSprite3D/AttackArea/CollisionAirPunch.disabled = false
- isAttacking = true
- if Input.is_action_pressed("move_down") and Input.is_action_pressed("KneeAttack"):
- $AnimatedSprite3D.play("KneeAttack")
- $snapPunch.play()
- $AnimatedSprite3D/AttackArea/CollisionAirPunch.disabled = false
- isAttacking = true
- elif is_on_floor():
- $AnimatedSprite3D/AttackArea/CollisionAirPunch.disabled = true
- 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":
- $AnimatedSprite3D/AttackArea/CollisionPunch.disabled = true
- isAttacking = false
- if $AnimatedSprite3D.animation == "reverse_kick":
- $AnimatedSprite3D/AttackArea/CollisionRearKick.disabled = true
- isAttacking = false
- if $AnimatedSprite3D.animation == "pick_up":
- isAttacking = false
- func _on_AttackArea_body_entered(body):
- if body.has_method("handle_hit"):
- body.handle_hit(damage)
- func _on_Area_area_entered(area):
- print(area.name, "entered")
- func _on_Area_area_exited(area):
- print(area.name, "exited")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement