I have a script that updates the position of my first person camera inside the player scene. I want to be able to check the physics settings to determine which function to use as follows:
extends Marker3D
# Updates the position of the camera
@onready var camera: Camera3D = $Camera3D
func _process(_delta: float) -> void:
# If physics interpolation do this:
# Reposition the camera using physics interpolated position since the
# camera was set to top_level true (keeps camera transforms global)
camera.position = get_global_transform_interpolated().origin
# If not physics interpolation do this:
#camera.position = global_position
Is there a function that checks the project settings?
Thank you, I knew it would be simple! I’ve got the documentation up at all times but if you don’t know what you’re looking for it can be hard to find the relevant information.
Just to clarify the correct syntax would be:
get_tree().physics_interpolation
Updated code:
extends Marker3D
# Updates the position of the camera
var interpolate_position: bool
@onready var camera: Camera3D = $Camera3D
func _ready() -> void:
interpolate_position = get_tree().physics_interpolation and \
physics_interpolation_mode != PHYSICS_INTERPOLATION_MODE_OFF
func _process(_delta: float) -> void:
if interpolate_position:
# Reposition the camera using physics interpolated position since the
# camera was set to top_level true (keeps camera transforms global)
camera.position = get_global_transform_interpolated().origin
else:
camera.position = global_position
EDIT:
Although the above works, it doesn’t take into account inherited physics interpolation.
I found a function that solves all of this:
extends Marker3D
# Updates the position of the camera
@onready var camera: Camera3D = $Camera3D
func _process(_delta: float) -> void:
if is_physics_interpolated_and_enabled():
# Reposition the camera using physics interpolated position since the
# camera was set to top_level true (keeps camera transforms global)
camera.position = get_global_transform_interpolated().origin
else:
camera.position = global_position