Replies: 2 comments 2 replies
-
In general there is a global method But Transform2D (and Transform3D too) also have a special method for interpolating - Example from documentation: var t = 0.0
func _physics_process(delta):
t += delta
$Monkey.transform = $Position1.transform.interpolate_with($Position2.transform, t) Also vectors (Vector2, Vector3) have a Example from documentation: const FOLLOW_SPEED = 4.0
func _physics_process(delta):
var mouse_pos = get_local_mouse_position()
$Sprite2D.position = $Sprite2D.position.lerp(mouse_pos, delta * FOLLOW_SPEED) Notice that in these examples the |
Beta Was this translation helpful? Give feedback.
-
For any unlucky souls who have gone down this very same rabbit hole, I've figured out a workaround: extends Node2D
class_name Interpolator
@export var target : Node2D
var _last : Transform2D = Transform2D.IDENTITY
var _current : Transform2D = Transform2D.IDENTITY
func get_global_transform_interpolated() -> Transform2D:
return _last.interpolate_with(_current, Engine.get_physics_interpolation_fraction())
func _enter_tree() -> void:
if !is_instance_valid(target):
target = get_parent()
_current = target.global_transform
_last = _current
top_level = true
physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF
global_transform = _current
func _physics_process(_delta: float) -> void:
_last = _current
_current = target.global_transform
func _process(_delta: float) -> void:
global_transform = get_global_transform_interpolated()
func _notification(what: int) -> void:
if what == NOTIFICATION_RESET_PHYSICS_INTERPOLATION:
if is_instance_valid(target):
_current = target.global_transform
_last = _current |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to get the interpolated transform in 2D or is it exclusively for 3D spatials? I'm using physics interpolation in 2D and am trying to smooth out the camera.
Beta Was this translation helpful? Give feedback.
All reactions