From ff268061d96626f56d3d58aff8dd24a23d58b6e0 Mon Sep 17 00:00:00 2001 From: Spencer Killen Date: Tue, 3 Jan 2023 16:32:59 -0700 Subject: [PATCH] floating --- godot/player/OnFootPhysics.gd | 6 +++++- godot/player/player.gd | 2 -- godot/player/player.tscn | 23 ++++++++++++++++++++++- godot/tests/test_player_locomotion.tscn | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/godot/player/OnFootPhysics.gd b/godot/player/OnFootPhysics.gd index 8b9ed34..567e3cf 100644 --- a/godot/player/OnFootPhysics.gd +++ b/godot/player/OnFootPhysics.gd @@ -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: diff --git a/godot/player/player.gd b/godot/player/player.gd index b47166c..69d75dd 100644 --- a/godot/player/player.gd +++ b/godot/player/player.gd @@ -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 diff --git a/godot/player/player.tscn b/godot/player/player.tscn index f9fcbab..ef038b7 100644 --- a/godot/player/player.tscn +++ b/godot/player/player.tscn @@ -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 ) diff --git a/godot/tests/test_player_locomotion.tscn b/godot/tests/test_player_locomotion.tscn index 7499159..6e7b01a 100644 --- a/godot/tests/test_player_locomotion.tscn +++ b/godot/tests/test_player_locomotion.tscn @@ -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