Skip to content

Commit

Permalink
Move all spring arm initializaiton code out of _process into _ready. R…
Browse files Browse the repository at this point in the history
…esolves ramokz#193
  • Loading branch information
ZenithStar committed May 1, 2024
1 parent a351bfb commit b4fd757
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions addons/phantom_camera/scripts/phantom_camera/phantom_camera_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,17 @@ func _ready():
if not Engine.is_editor_hint():
if not is_instance_valid(_follow_spring_arm):
_follow_spring_arm = SpringArm3D.new()
_follow_spring_arm.rotation = global_rotation
if is_instance_valid(follow_target):
_follow_spring_arm.position = _get_target_position_offset()
_follow_spring_arm.spring_length = spring_length
_follow_spring_arm.collision_mask = collision_mask
_follow_spring_arm.shape = shape
_follow_spring_arm.margin = margin
if not tween_on_load:
_has_tweened = true
get_parent().add_child.call_deferred(_follow_spring_arm)
reparent.call_deferred(_follow_spring_arm)
if follow_mode == FollowMode.FRAMED:
if not Engine.is_editor_hint():
_follow_framed_offset = global_position - _get_target_position_offset()
Expand Down Expand Up @@ -679,26 +685,11 @@ func _process(delta: float) -> void:
FollowMode.THIRD_PERSON:
if follow_target:
if not Engine.is_editor_hint():
if is_instance_valid(follow_target):
if is_instance_valid(_follow_spring_arm):
if not get_parent() == _follow_spring_arm:
var follow_target: Node3D = follow_target
_follow_spring_arm.rotation = rotation
_follow_spring_arm.global_position = _get_target_position_offset() # Ensure the PCam3D starts at the right position at runtime
_follow_spring_arm.spring_length = spring_length
_follow_spring_arm.collision_mask = collision_mask
_follow_spring_arm.shape = shape
_follow_spring_arm.margin = margin

if not tween_on_load:
_has_tweened = true

reparent(_follow_spring_arm)

_interpolate_position(
_get_target_position_offset(),
_follow_spring_arm
)
if is_instance_valid(follow_target) and is_instance_valid(_follow_spring_arm):
_interpolate_position(
_get_target_position_offset(),
_follow_spring_arm
)
else:
global_position = _get_position_offset_distance()

Expand Down

0 comments on commit b4fd757

Please sign in to comment.