Shrink collider when rolling
This commit is contained in:
parent
7e035e70c0
commit
252a6437d6
@ -1,10 +1,13 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
var gravity = 800
|
||||
var gravity = 900
|
||||
var gravity_mid = 500
|
||||
var gravity_fall = 1300
|
||||
const SPEED = 200.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
const roll_speed = 300
|
||||
var roll_cooldown_time = 0.5
|
||||
var colshape_stand = 30
|
||||
|
||||
@onready var sprite = $Sprites
|
||||
|
||||
@ -25,35 +28,14 @@ enum State {
|
||||
Roll,
|
||||
}
|
||||
|
||||
enum JumpState {
|
||||
}
|
||||
|
||||
func _play_anim(state: State, velocity: Vector2):
|
||||
match state:
|
||||
State.Idle:
|
||||
sprite.play("Idle")
|
||||
State.Run:
|
||||
sprite.play("Run")
|
||||
State.Walk:
|
||||
sprite.play("Walk")
|
||||
State.Jump:
|
||||
sprite.pause()
|
||||
sprite.set_frame_and_progress(0, 0)
|
||||
if velocity.y > 50:
|
||||
sprite.set_frame_and_progress(2,0)
|
||||
elif velocity.y > -150:
|
||||
sprite.set_frame_and_progress(1, 0)
|
||||
State.AirSpin:
|
||||
pass
|
||||
State.Land:
|
||||
sprite.play("Land")
|
||||
|
||||
func _process_velocity(state: State, delta):
|
||||
pass
|
||||
|
||||
func _physics_process(delta):
|
||||
if not is_on_floor():
|
||||
velocity.y += gravity * delta
|
||||
if velocity.y > 50:
|
||||
velocity.y += gravity_fall * delta
|
||||
elif velocity.y < -50:
|
||||
velocity.y += gravity * delta
|
||||
else:
|
||||
velocity.y += gravity_mid * delta
|
||||
elif state == State.Jump or state == State.AirSpin:
|
||||
state = State.Land
|
||||
sprite.play("Land")
|
||||
@ -65,6 +47,8 @@ func _physics_process(delta):
|
||||
state = State.Roll
|
||||
roll_time = 0.55
|
||||
roll_dir = -1 if sprite.flip_h else 1
|
||||
$CollisionShape2D.shape.size.y = colshape_stand / 2
|
||||
$CollisionShape2D.position.y = colshape_stand / -4
|
||||
sprite.play("GroundRoll")
|
||||
if Input.is_action_just_pressed("ui_accept") and state != State.Roll:
|
||||
if is_on_floor():
|
||||
@ -102,6 +86,8 @@ func _physics_process(delta):
|
||||
if roll_time >= 0:
|
||||
roll_time -= delta
|
||||
elif state == State.Roll:
|
||||
$CollisionShape2D.shape.size.y = colshape_stand
|
||||
$CollisionShape2D.position.y = colshape_stand / -2
|
||||
roll_cooldown = roll_cooldown_time
|
||||
state = State.Idle
|
||||
|
||||
@ -122,3 +108,30 @@ func _physics_process(delta):
|
||||
sprite.play("Idle")
|
||||
|
||||
move_and_slide()
|
||||
|
||||
# Maybe later
|
||||
enum JumpState {
|
||||
}
|
||||
|
||||
func _play_anim(state: State, velocity: Vector2):
|
||||
match state:
|
||||
State.Idle:
|
||||
sprite.play("Idle")
|
||||
State.Run:
|
||||
sprite.play("Run")
|
||||
State.Walk:
|
||||
sprite.play("Walk")
|
||||
State.Jump:
|
||||
sprite.pause()
|
||||
sprite.set_frame_and_progress(0, 0)
|
||||
if velocity.y > 50:
|
||||
sprite.set_frame_and_progress(2,0)
|
||||
elif velocity.y > -150:
|
||||
sprite.set_frame_and_progress(1, 0)
|
||||
State.AirSpin:
|
||||
pass
|
||||
State.Land:
|
||||
sprite.play("Land")
|
||||
|
||||
func _process_velocity(state: State, delta):
|
||||
pass
|
||||
|
@ -10,7 +10,8 @@ size = Vector2(500, 20)
|
||||
[node name="Node2D" type="Node2D"]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_ibeo8")]
|
||||
position = Vector2(163, 99)
|
||||
position = Vector2(251, 168)
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||
position = Vector2(265, 254)
|
||||
@ -22,3 +23,29 @@ mesh = SubResource("QuadMesh_n5vip")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||
shape = SubResource("RectangleShape2D_s46ls")
|
||||
|
||||
[node name="StaticBody2D2" type="StaticBody2D" parent="."]
|
||||
position = Vector2(331, 217)
|
||||
scale = Vector2(0.120002, 1)
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="MeshInstance2D" type="MeshInstance2D" parent="StaticBody2D2"]
|
||||
modulate = Color(0.168627, 0.678431, 0.701961, 1)
|
||||
scale = Vector2(500, 20)
|
||||
mesh = SubResource("QuadMesh_n5vip")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D2"]
|
||||
shape = SubResource("RectangleShape2D_s46ls")
|
||||
|
||||
[node name="StaticBody2D3" type="StaticBody2D" parent="."]
|
||||
position = Vector2(204, 234)
|
||||
scale = Vector2(0.120002, 1)
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="MeshInstance2D" type="MeshInstance2D" parent="StaticBody2D3"]
|
||||
modulate = Color(0.168627, 0.678431, 0.701961, 1)
|
||||
scale = Vector2(500, 20)
|
||||
mesh = SubResource("QuadMesh_n5vip")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D3"]
|
||||
shape = SubResource("RectangleShape2D_s46ls")
|
||||
|
@ -212,7 +212,7 @@ animations = [{
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"AirSpin",
|
||||
"speed": 10.0
|
||||
"speed": 8.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
@ -330,7 +330,7 @@ animations = [{
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"Run",
|
||||
"speed": 15.0
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
@ -363,7 +363,7 @@ animations = [{
|
||||
}]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_wc2sw"]
|
||||
size = Vector2(16, 29)
|
||||
size = Vector2(16, 30)
|
||||
|
||||
[node name="Player" type="CharacterBody2D"]
|
||||
script = ExtResource("1_23c20")
|
||||
@ -372,10 +372,9 @@ script = ExtResource("1_23c20")
|
||||
texture_filter = 1
|
||||
position = Vector2(0, -16)
|
||||
sprite_frames = SubResource("SpriteFrames_gvqqb")
|
||||
animation = &"GroundRoll"
|
||||
frame = 6
|
||||
frame_progress = 1.0
|
||||
animation = &"AirSpin"
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, -14.5)
|
||||
position = Vector2(0, -15)
|
||||
shape = SubResource("RectangleShape2D_wc2sw")
|
||||
|
Loading…
x
Reference in New Issue
Block a user