Skip to content

Commit

Permalink
Fix bug with interpolation.
Browse files Browse the repository at this point in the history
  • Loading branch information
belzecue committed Jan 22, 2023
1 parent ce29885 commit 9aef49f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Scripts/RigidBodyPhysicsTween.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ onready var visual_body: Spatial = get_node(visual_body_path)
onready var visual_body_target: Spatial = get_node(visual_body_target_path)

# Variables.
var visual_body_transform_old: Transform
var physics_body_trans_last: Transform
var physics_body_trans_current: Transform
var visual_body_velocity: float
var visual_body_velocity_previous: float

Expand All @@ -50,17 +51,18 @@ func _ready() -> void:
get_tree().quit()


func _physics_process(_delta: float) -> void:
func _physics_process(delta: float) -> void:
# Store current transform for physics body.
visual_body_transform_old = visual_body_target.global_transform
physics_body_trans_last = physics_body_trans_current
physics_body_trans_current = visual_body_target.global_transform


func _process(delta: float) -> void:
var visual_body_last_pos: Vector3 = visual_body.global_transform.origin

# Interpolate movement for visual body.
visual_body.global_transform = visual_body_transform_old.interpolate_with(
visual_body_target.global_transform,
visual_body.global_transform = physics_body_trans_last.interpolate_with(
physics_body_trans_current,
Engine.get_physics_interpolation_fraction()
)

Expand Down

1 comment on commit 9aef49f

@belzecue
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. Bug did not present for 3D, but did for 2D. Therefore, refactored 3D code accordingly.

Please sign in to comment.