Single View for Aim

James

Member
Hi, is it possible to utilize the same zoom perspective for Aim?

because each perspective uses two different set of arms its difficult to get the fingers in the exact same position for each.

So, when in 3rd person I'd like to use the zoom perspective for First as well as FP Perspective as well. Also, when not aiming Id like the system to return to the correct perspective.

When in 3rd , I aim and it changes to 1st person aim perspective but when not aiming it returns to 3rd only when in 3rd.

possible out of the box?
 
Just so I understand properly, you're using both 3rd and 1st person perspective, but you want zoom to always use 1st person perspective, then switch back to the perspective it was using previously?

You'll have to manually change viewtype when the Aim ability starts/stops, but that would be easy enough to do with a simple custom script that listens to the "OnAimAbilityStart" event. See this page for how to listen to events, and this page for info on the event's parameters. You can then simply use CameraController.SetViewType to change the current viewtype. You'd want to store the previous viewtype too, so that when the Aim ability ends, you can set it back to whatever it was previously.
 
Hey Andrew, that seems to work great but ran into an issue with it.

While in the Zoom State I can press V and it will swap the ViewType. Anyway to stop the viewtype from being set while in Zoom mode?

thanks again
 
That's controlled by "Can Change Perspectives" on the CameraController, so you should disable that. (You can set it in a state preset if needed.)
 
Looks like I had to also handle the "OnCameraChangePerspectives" or I wouldn't be able to return to state.

I originally did what you asked without the "OnCameraChangePerspectives" but I kept being stuck in FP mode. I added "OnCameraChangePerspectives" after and tracked the bool there. It works but I think there is a more elegant solution here?




using Opsive.Shared.Events;
using Opsive.Shared.Utility;
using Opsive.UltimateCharacterController.Camera;
using UnityEngine;

public class ZoomPerspective : MonoBehaviour
{

private CameraController _cc;
private string _lastViewType;
private string _zoomType = "Opsive.UltimateCharacterController.FirstPersonController.Camera.ViewTypes.Combat";
private bool _isFirstPerson;
private void Awake()
{
EventHandler.RegisterEvent<bool, bool>(gameObject, "OnAimAbilityStart", OnAimAbilityStart);
EventHandler.RegisterEvent<bool>(gameObject, "OnCameraChangePerspectives", OnCameraChangePerspectives);
}

void Start()
{
_cc = Camera.main.GetComponent<CameraController>();
_isFirstPerson = false;
}

private void OnCameraChangePerspectives(bool firstPerson)
{
//We only want to do this if allowed
if (!_cc.CanChangePerspectives) return;

//Track state of first person before zoom started.
_isFirstPerson = firstPerson;
}

private void OnAimAbilityStart(bool aiming, bool viaUser)
{
//Only want to use this if invoked by the player
if (!viaUser || _cc == null) return;

//Turn this feature off to avoid switching while in aim state.
_cc.CanChangePerspectives = false;

//If we are aiming...
if (aiming)
{
//Store the current view type so we can restore it later
_lastViewType = _cc.ActiveViewType.GetType().Name;

//Switch to first person combat
ChangeViewType(_zoomType);
}
else
{
//Don't do this if we haven't set a last view type
if (_lastViewType == null)
return;

//Allow perspective change
_cc.CanChangePerspectives = true;

//Restore the last perspective prior to zoom
ChangeViewType(_lastViewType);

//change perspective
_cc.SetPerspective(_isFirstPerson);

//Clear this now that we've used it
_lastViewType = null;
}
}

private void ChangeViewType(string viewType)
{
//Do this crazy thing
_cc.SetViewType(TypeUtility.GetType(viewType), true);
}
}
 
Top