Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends "res://Actors/ActorTemplate.gd"
- var motion = Vector2.ZERO
- var up = Vector2(0,-1)
- var snap_vec = Vector2.DOWN
- var sprite_flipped: bool
- func _ready():
- sprite_flipped = false
- func _physics_process(delta):
- move_and_animation()
- player_animations()
- motion = move_and_slide_with_snap(motion,snap_vec,up)
- apply_gravity()
- on_player_flip()
- func apply_gravity():
- motion.y += GRAVITY
- func move_and_animation():
- #Falling animation
- if ! is_on_floor() and motion.y > 0:
- $CharacterRig/AnimationPlayer.play("fall")
- #Move left / Aninmate left
- if Input.is_action_pressed("move_left"):
- sprite_flipped = true
- motion.x = lerp(motion.x -SPEED, -MAX_SPEED, ACCELERATION)
- if is_on_floor():
- $CharacterRig/AnimationPlayer.play("run")
- #Move right / Animate right
- elif Input.is_action_pressed("move_right"):
- sprite_flipped = false
- motion.x = lerp(motion.x +SPEED, +MAX_SPEED, ACCELERATION)
- if is_on_floor():
- $CharacterRig/AnimationPlayer.play("run")
- #When on floor with no input, stop player, animate idle
- else:
- motion.x = lerp(motion.x, 0, FRICTION)
- if is_on_floor() and $PlayerCollision/GroundDetection.is_colliding():
- $CharacterRig/AnimationPlayer.play("idle")
- #When on floor jump and animate jump
- if is_on_floor():
- if Input.is_action_just_pressed("jump"):
- motion.y = clamp(motion.y, 0, -JUMP)
- $CharacterRig/AnimationPlayer.play("jump")
- func player_animations():
- if Input.is_action_just_pressed("dance"):
- $CharacterRig/AnimationPlayer.play("dance")
- if Input.is_action_just_pressed("attack"):
- $CharacterRig/AnimationPlayer.play("attack")
- #Flip stuff for player (Sprite / Physics Collision)
- func on_player_flip():
- if sprite_flipped == true:
- $CharacterRig.scale.x = -1
- $PlayerCollision.scale.x = -1
- elif sprite_flipped == false:
- $CharacterRig.scale.x = 1
- $PlayerCollision.scale.x = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement