From f56e7fd00369d7b33a4c559f2cdb69cf487fd88f Mon Sep 17 00:00:00 2001 From: belzecue <1931303+belzecue@users.noreply.github.com> Date: Fri, 3 Feb 2023 22:33:31 +0800 Subject: [PATCH] Renaming and cleanup. --- Scripts/PlayerRBPhysTween.gd | 14 +++++++------- Scripts/RigidBodyPhysicsTween.gd | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Scripts/PlayerRBPhysTween.gd b/Scripts/PlayerRBPhysTween.gd index 0be766c..fa64ff6 100644 --- a/Scripts/PlayerRBPhysTween.gd +++ b/Scripts/PlayerRBPhysTween.gd @@ -17,7 +17,7 @@ onready var acceleration_orig: float = acceleration onready var max_velocity_orig: float = max_velocity onready var max_velocity_squared: float = max_velocity * max_velocity onready var max_velocity_squared_orig: float = max_velocity_squared -onready var linear_damp_orig: float = rigid_body.linear_damp +onready var linear_damp_orig: float = physics_body.linear_damp var input_velocity: Vector3 var is_grounded: bool = false # We start in air, falling. @@ -32,24 +32,24 @@ func _physics_process(delta: float) -> void: # Handle linear damping for air versus ground. if not was_grounded and is_grounded: # Air to Ground. - rigid_body.linear_damp = linear_damp_orig + physics_body.linear_damp = linear_damp_orig elif was_grounded and not is_grounded: # Ground to Air. - rigid_body.linear_damp = -1 + physics_body.linear_damp = -1 # Apply physics forces from input. if input_velocity != Vector3.ZERO: var adjusted_velocity: Vector3 = input_velocity * acceleration * (sixty_delta / delta) if is_grounded: # Grounded. - rigid_body.add_central_force( + physics_body.add_central_force( adjusted_velocity ) elif jump_move: # Not grounded and jump moving allowed. - var rbvsq: float = rigid_body.linear_velocity.length_squared() + var rbvsq: float = physics_body.linear_velocity.length_squared() if rbvsq < max_velocity_squared: - rigid_body.add_central_force( + physics_body.add_central_force( adjusted_velocity * lerp(1, 0, rbvsq / max_velocity_squared) # Throttle to max speed. ) @@ -60,7 +60,7 @@ func _physics_process(delta: float) -> void: if is_grounded: owner.playAudio(owner.mp3Whoosh, -24) - rigid_body.apply_central_impulse( + physics_body.apply_central_impulse( ground_normal * jump_strength * lerp(1, 3, (delta - sixty_delta) / 0.18333) # Fix for jump falloff as phys tick decreases. ) want_jump = false diff --git a/Scripts/RigidBodyPhysicsTween.gd b/Scripts/RigidBodyPhysicsTween.gd index 3cb5a43..9e6a272 100644 --- a/Scripts/RigidBodyPhysicsTween.gd +++ b/Scripts/RigidBodyPhysicsTween.gd @@ -27,7 +27,7 @@ export(NodePath) var visual_body_path: NodePath # Assigned nodes. -onready var rigid_body: RigidBody = get_node(rigid_body_path) +onready var physics_body: RigidBody = get_node(rigid_body_path) onready var visual_body: Spatial = get_node(visual_body_path) onready var visual_body_target: Spatial = get_node(visual_body_target_path) @@ -38,17 +38,17 @@ var visual_body_velocity: float var visual_body_velocity_previous: float -func _init() -> void: - # Switch off physics jitter fix because we are using manual interpolation. - # -> Move to game manager startup if many instances. - if Engine.physics_jitter_fix != 0: Engine.physics_jitter_fix = 0 - - func _ready() -> void: # Sanity checks. - if not rigid_body or not visual_body or not visual_body_target: - printerr("RidigBodyPhysicsTween Error: Missing assigned body for " + self.name) + if not physics_body or not visual_body or not visual_body_target: + printerr("PhysicsTween Error: Missing assigned body for " + self.name) get_tree().quit() + else: + physics_body_trans_current = physics_body.global_transform + physics_body_trans_last = physics_body.global_transform + visual_body.set_as_toplevel(true) # Unparent visual body transform from any parent. + set_process_priority(100) # Process other nodes first. + Engine.set_physics_jitter_fix(0.0) func _physics_process(delta: float) -> void: