Press Z or K to do a barrel roll fox!
This commit is contained in:
parent
7cb72e12cc
commit
307e277eae
@ -2,9 +2,11 @@ extends KinematicBody2D
|
|||||||
|
|
||||||
var velocity = Vector2.ZERO
|
var velocity = Vector2.ZERO
|
||||||
var input_vector = Vector2.ZERO
|
var input_vector = Vector2.ZERO
|
||||||
|
var roll_vector = Vector2.DOWN
|
||||||
|
|
||||||
const ACCELERATION = 500
|
const ACCELERATION = 500
|
||||||
const MAX_SPEED = 80
|
const MAX_SPEED = 80
|
||||||
|
const ROLL_SPEED = 120
|
||||||
const FRICTION = 500
|
const FRICTION = 500
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -28,7 +30,7 @@ func _process(delta):
|
|||||||
move_state(delta)
|
move_state(delta)
|
||||||
|
|
||||||
ROLL:
|
ROLL:
|
||||||
pass
|
roll_state(delta)
|
||||||
|
|
||||||
ATTACK:
|
ATTACK:
|
||||||
attack_state(delta)
|
attack_state(delta)
|
||||||
@ -37,9 +39,13 @@ func move_state(delta):
|
|||||||
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
|
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
|
||||||
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
|
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
|
||||||
input_vector = input_vector.normalized()
|
input_vector = input_vector.normalized()
|
||||||
|
|
||||||
if input_vector != Vector2.ZERO:
|
if input_vector != Vector2.ZERO:
|
||||||
|
roll_vector = input_vector
|
||||||
animationTree.set("parameters/Idle/blend_position", input_vector)
|
animationTree.set("parameters/Idle/blend_position", input_vector)
|
||||||
animationTree.set("parameters/Run/blend_position", input_vector)
|
animationTree.set("parameters/Run/blend_position", input_vector)
|
||||||
|
animationTree.set("parameters/Attack/blend_position", input_vector)
|
||||||
|
animationTree.set("parameters/Roll/blend_position", input_vector)
|
||||||
animationState.travel("Run")
|
animationState.travel("Run")
|
||||||
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
|
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
|
||||||
else:
|
else:
|
||||||
@ -47,19 +53,33 @@ func move_state(delta):
|
|||||||
animationState.travel("Idle")
|
animationState.travel("Idle")
|
||||||
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
|
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
|
||||||
|
|
||||||
velocity = move_and_slide(velocity)
|
#velocity = move_and_slide(velocity)
|
||||||
|
move()
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("roll"):
|
||||||
|
state = ROLL
|
||||||
|
|
||||||
if Input.is_action_just_pressed("attack"):
|
if Input.is_action_just_pressed("attack"):
|
||||||
state = ATTACK
|
state = ATTACK
|
||||||
|
|
||||||
|
func roll_animation_finished():
|
||||||
|
state = MOVE
|
||||||
|
|
||||||
|
func roll_state(delta):
|
||||||
|
velocity = roll_vector * ROLL_SPEED
|
||||||
|
animationState.travel("Roll")
|
||||||
|
move()
|
||||||
|
|
||||||
func attack_state(delta):
|
func attack_state(delta):
|
||||||
#velocity = Vector2.ZERO
|
#velocity = Vector2.ZERO
|
||||||
animationTree.set("parameters/Attack/blend_position", input_vector)
|
#animationTree.set("parameters/Attack/blend_position", input_vector)
|
||||||
animationState.travel("Attack")
|
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
|
animationState.travel("Attack")
|
||||||
#velocity = velocity.move_toward(Vector2.ZERO, FRICTION*delta)
|
#velocity = velocity.move_toward(Vector2.ZERO, FRICTION*delta)
|
||||||
#velocity = move_and_slide(velocity)
|
#velocity = move_and_slide(velocity)
|
||||||
|
|
||||||
|
func move():
|
||||||
|
velocity = move_and_slide(velocity)
|
||||||
|
|
||||||
func attack_aninimation_finished():
|
func attack_aninimation_finished():
|
||||||
state = MOVE
|
state = MOVE
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=42 format=2]
|
[gd_scene load_steps=53 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
|
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://Player/Player.png" type="Texture" id=2]
|
[ext_resource path="res://Player/Player.png" type="Texture" id=2]
|
||||||
@ -319,10 +319,129 @@ tracks/1/keys = {
|
|||||||
"values": [ true ]
|
"values": [ true ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=41]
|
||||||
|
resource_name = "RollDown"
|
||||||
|
length = 0.5
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath("Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
|
||||||
|
"update": 1,
|
||||||
|
"values": [ 55, 56, 57, 58, 59 ]
|
||||||
|
}
|
||||||
|
tracks/1/type = "method"
|
||||||
|
tracks/1/path = NodePath(".")
|
||||||
|
tracks/1/interp = 1
|
||||||
|
tracks/1/loop_wrap = true
|
||||||
|
tracks/1/imported = false
|
||||||
|
tracks/1/enabled = true
|
||||||
|
tracks/1/keys = {
|
||||||
|
"times": PoolRealArray( 0.499905 ),
|
||||||
|
"transitions": PoolRealArray( 1 ),
|
||||||
|
"values": [ {
|
||||||
|
"args": [ ],
|
||||||
|
"method": "roll_animation_finished"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=43]
|
||||||
|
resource_name = "RollLeft"
|
||||||
|
length = 0.5
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath("Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
|
||||||
|
"update": 1,
|
||||||
|
"values": [ 50, 51, 52, 53, 54 ]
|
||||||
|
}
|
||||||
|
tracks/1/type = "method"
|
||||||
|
tracks/1/path = NodePath(".")
|
||||||
|
tracks/1/interp = 1
|
||||||
|
tracks/1/loop_wrap = true
|
||||||
|
tracks/1/imported = false
|
||||||
|
tracks/1/enabled = true
|
||||||
|
tracks/1/keys = {
|
||||||
|
"times": PoolRealArray( 0.500823 ),
|
||||||
|
"transitions": PoolRealArray( 1 ),
|
||||||
|
"values": [ {
|
||||||
|
"args": [ ],
|
||||||
|
"method": "roll_animation_finished"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=42]
|
||||||
|
resource_name = "RollRight"
|
||||||
|
length = 0.5
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath("Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
|
||||||
|
"update": 1,
|
||||||
|
"values": [ 40, 41, 42, 43, 44 ]
|
||||||
|
}
|
||||||
|
tracks/1/type = "method"
|
||||||
|
tracks/1/path = NodePath(".")
|
||||||
|
tracks/1/interp = 1
|
||||||
|
tracks/1/loop_wrap = true
|
||||||
|
tracks/1/imported = false
|
||||||
|
tracks/1/enabled = true
|
||||||
|
tracks/1/keys = {
|
||||||
|
"times": PoolRealArray( 0.500364 ),
|
||||||
|
"transitions": PoolRealArray( 1 ),
|
||||||
|
"values": [ {
|
||||||
|
"args": [ ],
|
||||||
|
"method": "roll_animation_finished"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=44]
|
||||||
|
resource_name = "RollUp"
|
||||||
|
length = 0.5
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath("Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
|
||||||
|
"update": 1,
|
||||||
|
"values": [ 45, 46, 47, 48, 49 ]
|
||||||
|
}
|
||||||
|
tracks/1/type = "method"
|
||||||
|
tracks/1/path = NodePath(".")
|
||||||
|
tracks/1/interp = 1
|
||||||
|
tracks/1/loop_wrap = true
|
||||||
|
tracks/1/imported = false
|
||||||
|
tracks/1/enabled = true
|
||||||
|
tracks/1/keys = {
|
||||||
|
"times": PoolRealArray( 0.501281 ),
|
||||||
|
"transitions": PoolRealArray( 1 ),
|
||||||
|
"values": [ {
|
||||||
|
"args": [ ],
|
||||||
|
"method": "roll_animation_finished"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id=6]
|
[sub_resource type="Animation" id=6]
|
||||||
resource_name = "RunDown"
|
resource_name = "RunDown"
|
||||||
length = 0.6
|
length = 0.6
|
||||||
loop = true
|
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
tracks/0/path = NodePath("Sprite:frame")
|
tracks/0/path = NodePath("Sprite:frame")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
@ -437,6 +556,31 @@ min_space = Vector2( -1, -1.1 )
|
|||||||
max_space = Vector2( 1, 1.1 )
|
max_space = Vector2( 1, 1.1 )
|
||||||
blend_mode = 1
|
blend_mode = 1
|
||||||
|
|
||||||
|
[sub_resource type="AnimationNodeAnimation" id=45]
|
||||||
|
animation = "RollLeft"
|
||||||
|
|
||||||
|
[sub_resource type="AnimationNodeAnimation" id=46]
|
||||||
|
animation = "RollDown"
|
||||||
|
|
||||||
|
[sub_resource type="AnimationNodeAnimation" id=47]
|
||||||
|
animation = "RollRight"
|
||||||
|
|
||||||
|
[sub_resource type="AnimationNodeAnimation" id=48]
|
||||||
|
animation = "RollUp"
|
||||||
|
|
||||||
|
[sub_resource type="AnimationNodeBlendSpace2D" id=49]
|
||||||
|
blend_point_0/node = SubResource( 45 )
|
||||||
|
blend_point_0/pos = Vector2( -1, 0 )
|
||||||
|
blend_point_1/node = SubResource( 46 )
|
||||||
|
blend_point_1/pos = Vector2( 0, 1.1 )
|
||||||
|
blend_point_2/node = SubResource( 47 )
|
||||||
|
blend_point_2/pos = Vector2( 1, 0 )
|
||||||
|
blend_point_3/node = SubResource( 48 )
|
||||||
|
blend_point_3/pos = Vector2( 0, -1.1 )
|
||||||
|
min_space = Vector2( -1, -1.1 )
|
||||||
|
max_space = Vector2( 1, 1.1 )
|
||||||
|
blend_mode = 1
|
||||||
|
|
||||||
[sub_resource type="AnimationNodeAnimation" id=20]
|
[sub_resource type="AnimationNodeAnimation" id=20]
|
||||||
animation = "RunLeft"
|
animation = "RunLeft"
|
||||||
|
|
||||||
@ -474,15 +618,22 @@ blend_mode = 1
|
|||||||
|
|
||||||
[sub_resource type="AnimationNodeStateMachineTransition" id=39]
|
[sub_resource type="AnimationNodeStateMachineTransition" id=39]
|
||||||
|
|
||||||
|
[sub_resource type="AnimationNodeStateMachineTransition" id=50]
|
||||||
|
|
||||||
|
[sub_resource type="AnimationNodeStateMachineTransition" id=51]
|
||||||
|
|
||||||
[sub_resource type="AnimationNodeStateMachine" id=18]
|
[sub_resource type="AnimationNodeStateMachine" id=18]
|
||||||
states/Attack/node = SubResource( 35 )
|
states/Attack/node = SubResource( 35 )
|
||||||
states/Attack/position = Vector2( 321.375, 203.5 )
|
states/Attack/position = Vector2( 321.375, 203.5 )
|
||||||
states/Idle/node = SubResource( 15 )
|
states/Idle/node = SubResource( 15 )
|
||||||
states/Idle/position = Vector2( 323.5, 96.2812 )
|
states/Idle/position = Vector2( 323.5, 96.2812 )
|
||||||
|
states/Roll/node = SubResource( 49 )
|
||||||
|
states/Roll/position = Vector2( 325, -25.5 )
|
||||||
states/Run/node = SubResource( 24 )
|
states/Run/node = SubResource( 24 )
|
||||||
states/Run/position = Vector2( 509.5, 96.5 )
|
states/Run/position = Vector2( 509.5, 96.5 )
|
||||||
transitions = [ "Run", "Idle", SubResource( 25 ), "Idle", "Run", SubResource( 26 ), "Idle", "Attack", SubResource( 36 ), "Attack", "Idle", SubResource( 37 ), "Attack", "Run", SubResource( 38 ), "Run", "Attack", SubResource( 39 ) ]
|
transitions = [ "Run", "Idle", SubResource( 25 ), "Idle", "Run", SubResource( 26 ), "Idle", "Attack", SubResource( 36 ), "Attack", "Idle", SubResource( 37 ), "Attack", "Run", SubResource( 38 ), "Run", "Attack", SubResource( 39 ), "Roll", "Idle", SubResource( 50 ), "Idle", "Roll", SubResource( 51 ) ]
|
||||||
start_node = "Idle"
|
start_node = "Idle"
|
||||||
|
graph_offset = Vector2( -10, -78 )
|
||||||
|
|
||||||
[sub_resource type="AnimationNodeStateMachinePlayback" id=19]
|
[sub_resource type="AnimationNodeStateMachinePlayback" id=19]
|
||||||
|
|
||||||
@ -512,6 +663,10 @@ anims/IdleLeft = SubResource( 10 )
|
|||||||
anims/IdleRight = SubResource( 7 )
|
anims/IdleRight = SubResource( 7 )
|
||||||
anims/IdleUp = SubResource( 8 )
|
anims/IdleUp = SubResource( 8 )
|
||||||
anims/RESET = SubResource( 2 )
|
anims/RESET = SubResource( 2 )
|
||||||
|
anims/RollDown = SubResource( 41 )
|
||||||
|
anims/RollLeft = SubResource( 43 )
|
||||||
|
anims/RollRight = SubResource( 42 )
|
||||||
|
anims/RollUp = SubResource( 44 )
|
||||||
anims/RunDown = SubResource( 6 )
|
anims/RunDown = SubResource( 6 )
|
||||||
anims/RunLeft = SubResource( 4 )
|
anims/RunLeft = SubResource( 4 )
|
||||||
anims/RunRight = SubResource( 3 )
|
anims/RunRight = SubResource( 3 )
|
||||||
@ -523,11 +678,12 @@ anim_player = NodePath("../AnimationPlayer")
|
|||||||
parameters/playback = SubResource( 19 )
|
parameters/playback = SubResource( 19 )
|
||||||
parameters/Attack/blend_position = Vector2( 0, 0 )
|
parameters/Attack/blend_position = Vector2( 0, 0 )
|
||||||
parameters/Idle/blend_position = Vector2( 0, 0 )
|
parameters/Idle/blend_position = Vector2( 0, 0 )
|
||||||
|
parameters/Roll/blend_position = Vector2( -0.00132686, 0.00234544 )
|
||||||
parameters/Run/blend_position = Vector2( 0, 0 )
|
parameters/Run/blend_position = Vector2( 0, 0 )
|
||||||
|
|
||||||
[node name="HitboxPivot" type="Position2D" parent="."]
|
[node name="HitboxPivot" type="Position2D" parent="."]
|
||||||
position = Vector2( 0, -4 )
|
position = Vector2( 0, -4 )
|
||||||
rotation = 4.71239
|
rotation = 1.5708
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_gizmo_extents_": 8.0
|
"_gizmo_extents_": 8.0
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,16 @@ ui_down={
|
|||||||
}
|
}
|
||||||
attack={
|
attack={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":88,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":74,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":74,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
roll={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":75,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user