This commit is contained in:
Spencer Killen 2023-01-03 16:32:59 -07:00
parent f201a2182c
commit ff268061d9
Signed by: sjkillen
GPG Key ID: F307025B65C860BA
4 changed files with 28 additions and 5 deletions

View File

@ -5,7 +5,6 @@ onready var util = get_node("/root/Util")
export var gravity: float = 6.0
# When falling, gravity is artificially increased
export var gravity_downwards_factor: float = 3
export var float_factor = 0.5
export var ground_gravity: float = 3.1
# Rate of gaining speed
export var velocity_acceleration_xz: float = 3
@ -21,6 +20,8 @@ export var walk_factor: float = 2.0
export var can_glide: bool = false
export var can_float: bool = false
export var float_factor = 0.5
"public" var velocity: Vector3 = Vector3.ZERO
# Value changed by code only to add slow down or speed up effects
@ -49,6 +50,7 @@ func process_velocity(delta: float):
# Gravity
# You can buffer jumps by pressing releaseing the space bar and then pressing it again
if not is_on_floor():
$FloatFactorAnimation.advance(delta)
var grav = -gravity
if can_glide and Input.is_action_pressed("player_jump"):
grav /= 4
@ -59,6 +61,8 @@ func process_velocity(delta: float):
gdf = float_factor
target_velocity.y *= util.clamped_lerp(gdf, 1.0, velocity.y/2, 0.0)
else:
$FloatFactorAnimation.stop()
$FloatFactorAnimation.play("float_anim")
velocity.y = max(0.0, velocity.y)
target_velocity.y = max(0.0, max(target_velocity.y, jump_power * $"../MovementInput".jump_intent * jump_permission))
if target_velocity.y == 0.0 and velocity.y == 0.0:

View File

@ -4,7 +4,6 @@ onready var active_physics_node: Spatial = $OnFootPhysics
export var can_glide: bool = false
export var can_float: bool = false
export var float_factor = 0.5
func _ready():
Util.player = self
@ -38,6 +37,5 @@ func objective_distance() -> float:
func _process(_delta):
$OnFootPhysics.can_glide = can_glide
$OnFootPhysics.can_float = can_float
$OnFootPhysics.float_factor = float_factor

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=33 format=2]
[gd_scene load_steps=34 format=2]
[ext_resource path="res://player/CameraController.gd" type="Script" id=1]
[ext_resource path="res://player/OnFootPhysics.gd" type="Script" id=2]
@ -57,6 +57,22 @@ tracks/0/keys = {
[sub_resource type="CylinderShape" id=4]
[sub_resource type="Animation" id=14]
resource_name = "float_anim"
length = 5.0
tracks/0/type = "value"
tracks/0/path = NodePath(".:float_factor")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 3 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.5, 3.0 ]
}
[sub_resource type="SphereShape" id=5]
[sub_resource type="Animation" id=10]
@ -212,6 +228,11 @@ shape = SubResource( 4 )
[node name="Floor" type="RayCast" parent="OnFootPhysics"]
script = ExtResource( 10 )
[node name="FloatFactorAnimation" type="AnimationPlayer" parent="OnFootPhysics"]
autoplay = "float_anim"
playback_process_mode = 2
anims/float_anim = SubResource( 14 )
[node name="ElevatorPhysics" type="Spatial" parent="."]
script = ExtResource( 7 )

View File

@ -47,4 +47,4 @@ shape = SubResource( 2 )
[node name="Player" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.566872, 2.73697 )
can_glide = true
can_float = true