Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- onready var AS = $AnimatedSprite3D
- var velocity = Vector3()
- export var speed = 3
- export var gravity = 20
- export var jump = 7
- var isAttacking = false
- func _process(delta):
- _is_on_floor()
- var input_vector = Vector3.ZERO
- if is_on_floor():
- input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
- input_vector.z = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
- input_vector = input_vector.normalized()
- if input_vector != Vector3.ZERO:
- velocity.x = input_vector.x * speed
- velocity.z = input_vector.z * -speed
- AS.play("walk")
- isAttacking = false
- elif Input.is_action_pressed("attack") and is_on_floor():
- AS.play("punch")
- elif AS.animation == "punch" and $AnimatedSprite3D.frame !=2:
- return
- else:
- if not is_on_floor():
- velocity.y -= gravity * delta
- # if Input.is_action_pressed("ui_right"):
- velocity.z = 0
- isAttacking = false
- else:
- velocity.x = 0
- velocity.y = 0
- AS.play("idle")
- isAttacking = false
- if input_vector.x > 0:
- $AnimatedSprite3D.flip_h = false
- scale.x = 1
- elif input_vector.x < 0:
- $AnimatedSprite3D.flip_h = false
- scale.x = - 1
- func _is_on_floor():
- if Input.is_action_pressed("jump") and is_on_floor():
- velocity.y = jump
- velocity.z = 0
- AS.play("jump")
- isAttacking = false
- velocity = move_and_slide(velocity, Vector3.UP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement