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
- var input_vector = Vector3.ZERO
- onready var AttackArea = $AttackArea
- export (int) var damage := 10
- func _process(delta):
- if $AnimatedSprite3D.animation == "punch" and $AnimatedSprite3D.frame !=2:
- return
- apply_gravity()
- if is_on_floor() and not isAttacking:
- 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:
- 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"):
- $AnimatedSprite3D.play("punch")
- $AttackArea/CollisionShape.disabled = false
- velocity.x = 0
- velocity.z = 0
- isAttacking = true
- elif Input.is_action_just_pressed("reverse_kick"):
- velocity.x = 0
- velocity.z = 0
- $AnimatedSprite3D.play("reverse_kick")
- isAttacking = true
- elif Input.is_action_pressed("jump") and is_on_floor():
- velocity.z = 0
- velocity.x = 0
- AnimSprite.play("spring")
- isJumping = false
- elif Input.is_action_just_released("jump"):
- velocity.y = jump_impulse
- AnimSprite.play("jumping")
- isAttacking = false
- isJumping = 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
- 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
- if $AnimatedSprite3D.animation == "spring":
- $AttackArea/CollisionShape.disabled = true
- isAttacking = false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement