Hi, I want to toggle the Camera to move to a certain position by calling one function is it possible?
I've tried with MoveCameraTo() function but it's not working I'm not sure why.
Any way to do this? or can request the team to develop one simple function that passes in transform.position(vector 3) as a parameter, then the Camera can move to the position.
Move Camera To Desired Position (Vector 3)
Also interested on this, i'd want to teleport camera into new location and rotation,
but simply moving the transform there doesn't work.. (even if disable perspective cam during move)
unitycoder_com Hi! here are 3 code examples. I will update the plugin with these for the next update:
public void MoveCameraToInstant(Vector3 targetPosition)
{
finalOffset = targetPosition;
finalPosition = CalculateNewPosition(finalOffset, finalRotation, finalDistance);
ApplyToCamera();
}
public void MoveCameraTo(Vector3 targetPosition)
{
StopFollow();
Vector3 currentOffset = finalOffset;
disableMoves = true;
float lerp = 0;
Tween t = DOTween.To(() => lerp, x => lerp = x, 1, focusTweenDuration).SetEase(focusEase);
t.OnUpdate(() =>
{
finalOffset = Vector3.Lerp(currentOffset, targetPosition, lerp);
finalPosition = CalculateNewPosition(finalOffset, finalRotation, finalDistance);
ApplyToCamera();
})
.OnComplete(() =>
{
disableMoves = false;
});
}
public void MoveCameraTo(Vector3 targetPosition, Quaternion targetRotation, float targetDistance)
{
StopFollow();
Quaternion currentRot = finalRotation;
float currentDist = finalDistance;
Vector3 currentOffset = finalOffset;
disableMoves = true;
float lerp = 0;
Tween t = DOTween.To(() => lerp, x => lerp = x, 1, focusTweenDuration).SetEase(focusEase);
t.OnUpdate(() =>
{
finalOffset = Vector3.Lerp(currentOffset, targetPosition, lerp);
finalRotation = Quaternion.Lerp(currentRot, targetRotation, lerp);
finalDistance = Mathf.Lerp(currentDist, targetDistance, lerp);
finalPosition = CalculateNewPosition(finalOffset, finalRotation, finalDistance);
ApplyToCamera();
})
.OnComplete(() =>
{
currentPitch = Pitch = targetRotation.eulerAngles.x;
currentYaw = Yaw = targetRotation.eulerAngles.y;
disableMoves = false;
});
}
thanks! MoveCameraTo works perfectly (only adjusted the focusTweenDuration to 0 for my use case)
possible bug:
using MoveCameraTo(Vector3 targetPosition, Quaternion targetRotation, float targetDistance),
after teleport with that: if you do pinch or pan, it breaks (camera flies away or gets stuck)
so i'm guessing some previous-value causes that?
unitycoder_com I don't have this issue on my side, are you sure you don't have another script modifying the values?
I will release a big update in the upcoming days, with the officiel implementations for the MoveCameraTo() API, with a demo scene:
unitycoder_com the new version is now available in the asset store! I would suggest to back up the current Exoa folder just in case, then remove it before importing the new package. It's a complete rewritten version and fully commented/documented.
upgraded to 3.0, now testing teleporting on FreeCam,
but seems like camera is not moving when calling those methods?
tested this on free cam demo scene,
`using UnityEngine;
public class MoveCamTest : MonoBehaviour
{
public Exoa.Cameras.CameraFree freeCam;
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
Debug.Log("teleport");
freeCam.MoveCameraToInstant(Vector3.zero, 10, Quaternion.identity);
}
}
}
`
unitycoder_com you're right, these API methods work for all cameras but not for the CameraFree mode as it's still a WIP. But I will try to fix that asap and send you an update.
Thanks!
- Edited
Regarding the MoveCameraTo function, would it be possible to add options to
- allow the user to pan the camera during an animated move (and break out of the animated move when they do so)
- and/or set the speed of the animated move
My issue with it currently is, that it takes control away from the player for too long even after the move is seemingly complete already, which might also be good to be looked at (I'm assuming it's lerping some very small amounts there in the end which isn't really visible but still blocks user interaction?)
- Edited
sakus
The "half life" variable let you change the animation speed. And as you are suggesting, I'm adding another parameter "distance from target to concider completed" to avoid the animation from blocking the user. It will be in the next update!
About stopping the focus if the user moves, this is not supported as it could need a lot of customization, but you could detect the user's input and call StopFollow() when you need to stop the animation.
unitycoder_com I just published an update with teleporting on freecam
Ah I missed the half life variable, thanks. OK, if I can stop the animation with StopFollow I'll look into doing it myself with that.
Now I'll just wait for the distance from target option to make it responsive to user's panning as soon as the animation is close enough to finished.
Thanks!
Anthony
Ha so it seems, awesome!
Seems to be working fine, I might not even have to completely cancel the animation after all, might be able to make it snappy yet smooth enough with these (working on a turn based strategy prototype where selecting an unit will center the camera on said unit, but I find myself wanting to start panning the view right away afterwards)
Anthony
is there any updates on this I am trying to use free cam + OnClickMoveToObjPosition together to focus on points of a 3d model. I would like to create a orbit camera that can focus on positions. It works pretty well together but I notice that it prioritizes distance over position and rotation. When I click the focus button it does not go to the position unless the camera has zoomed