Skip to content

Commit

Permalink
Renaming and cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
belzecue committed Feb 3, 2023
1 parent 9aef49f commit f56e7fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions Scripts/PlayerRBPhysTween.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
)

Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions Scripts/RigidBodyPhysicsTween.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand Down

0 comments on commit f56e7fd

Please sign in to comment.