Pseudo3D View Type Aim reset on no input?

m3nth0l

New member
Not sure the best way to word this - I'm looking for a way to reset the rotation of the weapon when the right stick is returned to center, but not sure about the best way to go about it. I've tried creating a new view type to reset but have been unsuccessful with rotating back to the forward position. Any ideas?
 
Ok, so after messing with this more I got it snapping by overriding the LookDirection like this:

C#:
using UnityEngine;
using Opsive.UltimateCharacterController.ThirdPersonController.Camera.ViewTypes;
using Opsive.UltimateCharacterController.Input;
using Opsive.UltimateCharacterController.Utility;

public class SnapAim : Pseudo3D
{
    private PlayerInput m_PlayerInput;

    public override void AttachCharacter(GameObject character)
    {
        base.AttachCharacter(character);

        if (m_Character == null) {
            m_PlayerInput = null;
        } else {
            m_PlayerInput = m_Character.GetCachedComponent<PlayerInput>();
        }
    }
   
    public override Vector3 LookDirection(Vector3 lookPosition, bool characterLookDirection, int layerMask, bool useRecoil)
    {
        var direction = Vector3.zero;
        direction.x = m_PlayerInput.GetAxis(m_PlayerInput.HorizontalLookInputName);
        direction.y = -m_PlayerInput.GetAxis(m_PlayerInput.VerticalLookInputName);
        return direction.sqrMagnitude > 0.1f ? direction : m_CharacterTransform.forward;
    }
}

It works, but is the best way to do this?
Also, If you stop mid way through rotating to 12 or 6 o'clock on the right stick the character does not adhere to the rotation limits I set, so I still need to work that out as well.
 
Last edited:
Overriding the LookDirection is the correct way. I try to avoid referencing the PlayerInput class directly within the MovementType because the movement type can be used by non-player controlled characters, but in your case you are probably ok doing that.

If the joystick is stopped mid way through is the direction magnitude positive?
 
Thanks Justin, yes direction.sqrMagnitude logs only positive values when stopped midway.
 
Last edited:
Oops, I confused myself. You are overriding the ViewType, whereas I was thinking MovementType. For the ViewType it is safe to get the PlayerInput component because the camera can only be attached to a Ultimate Character Controller character.
 
Top