Can anyone suggest how to smoothly move an object that is inside a hierarchy? There is a specific task. The camera is a child of the player, and must remain within the hierarchy. At the same time, I want it to follow the player object with a delay. In Unreal Engine, the CameraLag setting in the SpringArm component is responsible for this.
Camera stuff is pretty tricky… you may wish to consider using Cinemachine from the Unity Package Manager.
There’s even a dedicated forum: Unity Engine - Unity Discussions
Otherwise perhaps some type of Lerp-based low-pass filtering on the position / rotation might work.
Lerping to smooth things out:
Cinemachine has stuff that does this work for you, but let’s say you wanted to do this yourself.
Even though every object inside a hierarchy keeps its own transform.localPosition
, there’s nothing wrong with using the transform.position
world coordinates to do various “adjustments.”
One approach is the history approach. Every Update(), enqueue your player’s position and rotation and time, and dequeue until your history is 200ms long. In LateUpdate() [the best time to be doing corrections on things like camera positioning], peek at the oldest item in the queue and calculate your position relative to that point.