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.
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().
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().
@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);
}