Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- onready var animatedSprite = $AnimatedSprite3D
- var movement = Vector3();
- var up = Vector3();
- var speed = 70;
- var isAttacking = false;
- var isJumping = false;
- var gravity = -30;
- var jump_impulse = 320
- onready var AttackArea = $AttackArea
- export (int) var damage := 10
- func _process(delta):
- apply_gravity(delta)
- #jump()
- if Input.is_action_pressed("move_right") && isAttacking == false:
- movement.x = speed;
- $AnimatedSprite3D.play("walk");
- elif Input.is_action_pressed("move_left") && isAttacking == false:
- movement.x = -speed;
- $AnimatedSprite3D.play("walk");
- elif Input.is_action_pressed("move_up") && isAttacking == false:
- movement.z = -speed;
- $AnimatedSprite3D.play("walk");
- elif Input.is_action_pressed("move_down") && isAttacking == false:
- movement.z = speed;
- $AnimatedSprite3D.play("walk");
- else:
- movement.x = 0;
- movement.z = 0;
- if isAttacking == false:
- $AnimatedSprite3D.play("idle");
- if movement.x > 0:
- animatedSprite.flip_h = false
- elif movement.x < 0:
- animatedSprite.flip_h = true
- if Input.is_action_just_pressed("reverse_kick"):
- $AnimatedSprite3D.play("reverse_kick");
- isAttacking = true;
- if Input.is_action_just_pressed("punch"):
- $AnimatedSprite3D.play("punch");
- isAttacking = true;
- $AttackArea/CollisionShape.disabled = false;
- if is_on_floor() && Input.is_action_just_pressed("jump"):
- movement.y = jump_impulse;
- elif !is_on_floor():
- $AnimatedSprite3D.play("jumping");
- isAttacking = false;
- movement = move_and_slide(movement, Vector3.UP * delta);
- return movement.normalized();
- func apply_gravity(delta):
- movement.y = movement.y + gravity;
- #func jump():
- #if is_on_floor() && Input.is_action_pressed("jump"):
- #isJumping = true;
- #movement.y = jump_impulse;
- func _on_AnimatedSprite3D_animation_finished():
- if $AnimatedSprite3D.animation == "punch":
- #get_node("AnimatedSprite3D").play("idle")
- $AttackArea/CollisionShape.disabled = true
- isAttacking = false
- # var col = get_node("CollisionShape")
- # get_node("AnimatedSprite3D").play("punch")
- # isAttacking = false;
- # $AttackArea/CollisionShape.disabled = true;
- # print (col.is_disabled())
- get_node("AnimatedSprite3D").play("jumping")
- isAttacking = false;
- isJumping = 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