Animations & Movement tweaks
This commit is contained in:
@ -3,13 +3,14 @@ extends KinematicBody2D
|
||||
export var clearance_level = 0
|
||||
|
||||
# Environment variables
|
||||
export var baseGravity : float = 9.8
|
||||
var baseGravity : float = 9.8
|
||||
|
||||
# Player movment variables
|
||||
export var maxMoveVelocity : float = 300
|
||||
export var moveAcceleration : float = 15
|
||||
export var moveFriction : float = 45
|
||||
export var jumpVelocity : float = -150
|
||||
var maxMoveVelocity : float = 150
|
||||
var moveAcceleration : float = 25
|
||||
var moveFriction : float = 65
|
||||
var jumpVelocity : float = -150
|
||||
var jumped = false
|
||||
|
||||
var moveMotion : float = 0 # Player Input ( <- & -> )
|
||||
var motion : Vector2 = Vector2(0,0) # Player's current velocity
|
||||
@ -25,7 +26,7 @@ func add_item(item):
|
||||
equip_item(item)
|
||||
|
||||
func equip_item(item):
|
||||
var node = get_node_or_null("Torso/RightArm/RightForearm/LeftHand/Node2D/" + item)
|
||||
var node = get_node_or_null("Sprite/Torso/RightArm/RightForearm/LeftHand/Node2D/" + item)
|
||||
if node:
|
||||
equiped = item
|
||||
node.show()
|
||||
@ -40,6 +41,7 @@ func remove_interactable(interactable):
|
||||
interactables.remove(loc)
|
||||
|
||||
func _physics_process(delta):
|
||||
jumped = false
|
||||
|
||||
# Gravity
|
||||
motion.y += baseGravity
|
||||
@ -67,8 +69,11 @@ func user_input():
|
||||
interactables[0].interact()
|
||||
|
||||
if is_on_floor() and Input.is_action_just_pressed("ui_up") and Input.is_action_pressed("ui_down"):
|
||||
position.y = position.y + 2
|
||||
return
|
||||
var test_pos = Vector2(position.x,position.y+5)
|
||||
|
||||
if not test_move(Transform2D(0,test_pos), Vector2(0,8)):
|
||||
position.y = position.y + 8
|
||||
return
|
||||
|
||||
if(Input.is_action_pressed("ui_left")):
|
||||
moveMotion -= moveAcceleration
|
||||
@ -77,6 +82,7 @@ func user_input():
|
||||
|
||||
if(is_on_floor() and Input.is_action_just_pressed("ui_up")):
|
||||
motion.y = jumpVelocity
|
||||
jumped = true
|
||||
|
||||
if is_on_floor() and (!Input.is_action_pressed("ui_left") and !Input.is_action_pressed("ui_right")):
|
||||
if moveMotion > 0:
|
||||
@ -86,12 +92,19 @@ func user_input():
|
||||
|
||||
func animation_manager(motion : float):
|
||||
|
||||
if moveMotion > 0:
|
||||
if not is_on_floor():
|
||||
$AnimationPlayer.play("InAir")
|
||||
elif jumped:
|
||||
if $AnimationPlayer.current_animation != "Jump":
|
||||
$AnimationPlayer.play("Jump")
|
||||
elif moveMotion > 0:
|
||||
$AnimationPlayer.playback_speed = abs(motion)/200
|
||||
$AnimationPlayer.play("RunRight")
|
||||
if $AnimationPlayer.current_animation != "RunRight":
|
||||
$AnimationPlayer.play("RunRight")
|
||||
elif moveMotion < 0:
|
||||
$AnimationPlayer.playback_speed = abs(motion)/200
|
||||
$AnimationPlayer.play("RunLeft")
|
||||
if $AnimationPlayer.current_animation != "RunLeft":
|
||||
$AnimationPlayer.play("RunLeft")
|
||||
else:
|
||||
$AnimationPlayer.playback_speed = 1
|
||||
$AnimationPlayer.play("Idle")
|
||||
|
Reference in New Issue
Block a user