Target Group doesn't work with OnTargetObjectWarped

Hello im making a 2D space shooter. and the players can warp to another side of the map. I have a virtual camera Following a target group containing the players.

When the target group warp the OnTargetObjectWarped isn’t working properly. I’ve notice it does work in a demo project where it will just follow a gameobject but doesn’t work when following a target group. Please help.

private void OnTriggerExit2D(Collider2D other) {
    if (other.name.Equals("PlayerArena")) {
        Vector3 newPosition = Utilities.Vector2OppositeSideOfSquare(other.transform, innerArenaBoxCollider2D, 1.5f);
        Vector3 movementDelta = newPosition - other.transform.position);
        other.transform.position = newPosition;
        MoveObjectsInArena(playersHolderTransform);
        virtualCamera.OnTargetObjectWarped(playersGroup, movementDelta);
        if (OnPlayerArenaTeleport != null) 
            OnPlayerArenaTeleport();
    }
}

The group’s position gets updated, based on the positions of its members, in the group’s Update() or LateUpdate(), depending on what you’ve selected. Is it possible that you’re calling OnTargetObjectWarped() before the group has updated its position? Try moving the group also in MoveObjectsInArena().

1 Like

Thank you so much for helping me. I was using fixed update for my cinemachine brain vcam update method. Changing it to smart update or late update fixes it but the camera moves choppy. I’m assuming the fixed update is being called before the OnTargetObjectWarped() is called which is being called from theOnTriggerExit2D(). I’ll do more digging to fix this new issue

The group updates its own position, and has its own update method setting, The brain is not involved here. Looking at your code, there is no opportuniity for the group to update, since you are moving the objects then immediately calling OnTargetObjectWarped().

I am new at this. How would i update the target group? I don’t see an API call method in target group to update it.

@Gregoryl So I’ve been playing around OnTargetObjectWarp and it still doesn’t seem like it works when your using a target group. I have the target group set update method on Update. So i get the old frame, wait for it to render. i can see in debug.log() the position changes. but when i call the OnTargetObjectWarped() it still doesn’t work. I don’t know what to do at this point besides scrapping cinemachine and going back to the old way

private void OnTriggerExit2D(Collider2D other) {
    if (other.name.Equals("PlayerArena")) {
       
        Vector3 newPosition = Utilities.Vector2OppositeSideOfSquare(other.transform, innerArenaBoxCollider2D, 1.5f);
        other.transform.position = newPosition; // Warps my GameObjects
        MoveObjectsInArena(playersHolderTransform);// Warps my GameObjects
       
        StartCoroutine(WaitForMoveCamera());
    }
}

IEnumerator WaitForMoveCamera() {
    Vector3 oldPosition = playersGroup.transform.position; //Get old position of target group
    Debug.Log(oldPosition);
    yield return new WaitForEndOfFrame();
    Vector3 newPosition = playersGroup.transform.position; //Gets the new position after it updates
    Debug.Log(newPosition);
    virtualCamera.OnTargetObjectWarped(playersGroup, oldPosition - newPosition);
}




5096969--502352--Annotation 2019-10-22 225137.png

That approach should work. I think maybe it’s just that your delta is wrong. Try this instead:

virtualCamera.OnTargetObjectWarped(playersGroup, newPosition - oldPosition);
1 Like