A
A
Alexander Pianov2019-11-10 17:55:10
C++ / C#
Alexander Pianov, 2019-11-10 17:55:10

Where does the backlash of the camera come from when observing clones of an object?

There is a main unit in the scene that can capture the spawn that creates clones of it.
When you click on the created unit, the "control ID" changes to the ID of this unit, and the camera smoothly moves towards it:

public void Update()
    {
        if (Player[ID] != null && (battleTap == true || supportTap == true))
        {
            CameraTracking();
        }
    }

public void CameraTracking()
    {
        cam.Camera.transform.position = Vector3.SmoothDamp(cam.Camera.transform.position,
                    Player[ID].GetComponentInChildren<Camera>().transform.position,
                    ref cam.m_MoveVelocity, cam.m_DampTime);
    }

All units have an easy camera shift script installed:
private void Start()
    {
        _offset = transform.position - PlayerCamera.transform.position;
    }

private void Update()
    {
        transform.position = PlayerCamera.transform.position + _offset;
    }

Everything works great at the beginning. However, if you turn off and then turn on the main unit in the inspector, there will be a barely noticeable backlash of the camera.
Moreover, it appears when observing spawned clones of a unit - this is hardly noticeable, but it has a place to be.
Backlash disappears when moving to the main unit. When saving changes in Visual Studio, the backlash disappears for all units. What could it be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pyanov, 2019-11-11
@pr9niks

Found the answer myself, it's all about Update:
"Often LateUpdate is used for a 3rd person stalking camera. If you move and rotate a character in Update, you can do all the camera movement and rotation calculations in LateUpdate. This will ensure that the character moves up to how the camera will track his position."
Decision:

public void LateUpdate()
    {
        if (Player[ID] != null && (battleTap == true || supportTap == true))
        {
            CameraTracking();
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question