Clean the input and movement code
This commit is contained in:
parent
79c2820b3d
commit
e57e16eee7
2 changed files with 23 additions and 34 deletions
31
player.gd
31
player.gd
|
@ -3,17 +3,10 @@ extends CharacterBody2D
|
||||||
|
|
||||||
const SPEED = 500.0
|
const SPEED = 500.0
|
||||||
|
|
||||||
|
func get_input():
|
||||||
|
|
||||||
func _physics_process(delta):
|
|
||||||
|
|
||||||
|
|
||||||
#region Movement
|
|
||||||
# Get the input direction and handle the movement/deceleration.
|
|
||||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
|
||||||
var directionX = Input.get_axis("move_left", "move_right")
|
var directionX = Input.get_axis("move_left", "move_right")
|
||||||
var directionY = Input.get_axis("move_up", "move_down")
|
var directionY = Input.get_axis("move_up", "move_down")
|
||||||
|
# Get the input direction and handle the movement/deceleration.
|
||||||
if directionX :
|
if directionX :
|
||||||
velocity.x = directionX * SPEED
|
velocity.x = directionX * SPEED
|
||||||
else:
|
else:
|
||||||
|
@ -22,16 +15,14 @@ func _physics_process(delta):
|
||||||
velocity.y = directionY * SPEED
|
velocity.y = directionY * SPEED
|
||||||
else:
|
else:
|
||||||
velocity.y = move_toward(velocity.y, 0, SPEED)
|
velocity.y = move_toward(velocity.y, 0, SPEED)
|
||||||
#endregion
|
|
||||||
|
#region Animation
|
||||||
|
if (directionX < 0):
|
||||||
|
$Skeleton2D/root/Hips.set_scale(Vector2(1, 1))
|
||||||
|
if (directionX > 0):
|
||||||
|
$Skeleton2D/root/Hips.set_scale(Vector2(-1, 1))
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Animation
|
func _physics_process(delta):
|
||||||
|
get_input()
|
||||||
var WalkLeft = directionX < 0 or (directionY < 0 and directionY != 0)
|
|
||||||
var Idle = (velocity.x == 0 and velocity.y == 0)
|
|
||||||
$AnimationTree.set("parameters/Locomotion/conditions/Idle",Idle)
|
|
||||||
$AnimationTree.set("parameters/Locomotion/conditions/WalkLeft",WalkLeft and !Idle )
|
|
||||||
$AnimationTree.set("parameters/Locomotion/conditions/WalkRight",!WalkLeft and !Idle)
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
26
player.tscn
26
player.tscn
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=29 format=3 uid="uid://0m1hk2nu4bps"]
|
[gd_scene load_steps=30 format=3 uid="uid://0m1hk2nu4bps"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://player.gd" id="1_0pgv8"]
|
[ext_resource type="Script" path="res://player.gd" id="1_0pgv8"]
|
||||||
[ext_resource type="Texture2D" uid="uid://5pmqr3y62guu" path="res://player/currentCloth.tres" id="2_45h8h"]
|
[ext_resource type="Texture2D" uid="uid://5pmqr3y62guu" path="res://player/currentCloth.tres" id="2_45h8h"]
|
||||||
|
@ -514,7 +514,6 @@ transitions = ["Start", "idle", SubResource("AnimationNodeStateMachineTransition
|
||||||
graph_offset = Vector2(-292, -6)
|
graph_offset = Vector2(-292, -6)
|
||||||
|
|
||||||
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_wgp38"]
|
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_wgp38"]
|
||||||
graph_offset = Vector2(-182.362, 30.8934)
|
|
||||||
nodes/Blend2/node = SubResource("AnimationNodeBlend2_ydofw")
|
nodes/Blend2/node = SubResource("AnimationNodeBlend2_ydofw")
|
||||||
nodes/Blend2/position = Vector2(380, 180)
|
nodes/Blend2/position = Vector2(380, 180)
|
||||||
nodes/Locomotion/node = SubResource("AnimationNodeStateMachine_x16w7")
|
nodes/Locomotion/node = SubResource("AnimationNodeStateMachine_x16w7")
|
||||||
|
@ -545,10 +544,11 @@ editor_draw_limits = true
|
||||||
libraries = {
|
libraries = {
|
||||||
"": SubResource("AnimationLibrary_4k813")
|
"": SubResource("AnimationLibrary_4k813")
|
||||||
}
|
}
|
||||||
autoplay = "player_WalkLeft"
|
autoplay = "idle"
|
||||||
playback_default_blend_time = 0.3
|
playback_default_blend_time = 0.3
|
||||||
|
|
||||||
[node name="AnimationTree" type="AnimationTree" parent="." groups=["Animation"]]
|
[node name="AnimationTree" type="AnimationTree" parent="." groups=["Animation"]]
|
||||||
|
active = false
|
||||||
tree_root = SubResource("AnimationNodeBlendTree_wgp38")
|
tree_root = SubResource("AnimationNodeBlendTree_wgp38")
|
||||||
anim_player = NodePath("../AnimationPlayer")
|
anim_player = NodePath("../AnimationPlayer")
|
||||||
parameters/Blend2/blend_amount = 0
|
parameters/Blend2/blend_amount = 0
|
||||||
|
@ -561,22 +561,21 @@ parameters/Locomotion/Walkspace/blend_position = Vector2(-0.00198412, 0.923077)
|
||||||
position = Vector2(17, 0)
|
position = Vector2(17, 0)
|
||||||
|
|
||||||
[node name="BootL" type="Sprite2D" parent="Skeleton2D"]
|
[node name="BootL" type="Sprite2D" parent="Skeleton2D"]
|
||||||
position = Vector2(-96.8819, -35.0051)
|
position = Vector2(7.14621, -39.4955)
|
||||||
rotation = 0.435284
|
rotation = -0.28458
|
||||||
scale = Vector2(1, 1)
|
|
||||||
texture = ExtResource("2_45h8h")
|
texture = ExtResource("2_45h8h")
|
||||||
region_enabled = true
|
region_enabled = true
|
||||||
region_rect = Rect2(896, 768, 128, 128)
|
region_rect = Rect2(896, 768, 128, 128)
|
||||||
|
|
||||||
[node name="BootR" type="Sprite2D" parent="Skeleton2D"]
|
[node name="BootR" type="Sprite2D" parent="Skeleton2D"]
|
||||||
position = Vector2(42.9032, -41.0059)
|
position = Vector2(-42.4149, -46.2448)
|
||||||
rotation = -0.698758
|
rotation = 0.193006
|
||||||
texture = ExtResource("2_45h8h")
|
texture = ExtResource("2_45h8h")
|
||||||
region_enabled = true
|
region_enabled = true
|
||||||
region_rect = Rect2(896, 768, 128, 128)
|
region_rect = Rect2(896, 768, 128, 128)
|
||||||
|
|
||||||
[node name="Body" type="Sprite2D" parent="Skeleton2D"]
|
[node name="Body" type="Sprite2D" parent="Skeleton2D"]
|
||||||
position = Vector2(59, -231)
|
position = Vector2(51, -232.802)
|
||||||
texture = ExtResource("2_45h8h")
|
texture = ExtResource("2_45h8h")
|
||||||
offset = Vector2(-15, 0)
|
offset = Vector2(-15, 0)
|
||||||
region_enabled = true
|
region_enabled = true
|
||||||
|
@ -597,17 +596,16 @@ region_rect = Rect2(768, 768, 128, 128)
|
||||||
|
|
||||||
[node name="Tail" type="Sprite2D" parent="Skeleton2D/Body"]
|
[node name="Tail" type="Sprite2D" parent="Skeleton2D/Body"]
|
||||||
show_behind_parent = true
|
show_behind_parent = true
|
||||||
position = Vector2(36, 101)
|
position = Vector2(44, 102.802)
|
||||||
rotation = -0.132128
|
rotation = 0.153589
|
||||||
texture = ExtResource("2_45h8h")
|
texture = ExtResource("2_45h8h")
|
||||||
offset = Vector2(70, 0)
|
offset = Vector2(70, 0)
|
||||||
region_enabled = true
|
region_enabled = true
|
||||||
region_rect = Rect2(768, 640, 256, 128)
|
region_rect = Rect2(768, 640, 256, 128)
|
||||||
|
|
||||||
[node name="Head" type="Sprite2D" parent="Skeleton2D"]
|
[node name="Head" type="Sprite2D" parent="Skeleton2D"]
|
||||||
position = Vector2(-32, -404)
|
position = Vector2(-40, -405.802)
|
||||||
rotation = 0.0756305
|
rotation = 0.0245451
|
||||||
scale = Vector2(1, 1)
|
|
||||||
texture = ExtResource("2_45h8h")
|
texture = ExtResource("2_45h8h")
|
||||||
offset = Vector2(0, -168)
|
offset = Vector2(0, -168)
|
||||||
region_enabled = true
|
region_enabled = true
|
||||||
|
|
Loading…
Reference in a new issue