Third Person Adventure but with forward/backward movement relative to camera direction

DarkLiKally

New member
Hello together,

I'm using Cinemachine for all kinds of camera settings in the game. It's third person and therefore I'm using UCC with third person.
I need exactly everything like it is set up in the RPG movement type. Except one thing - I want be able to rotate the camera around the character while he's standing still - that's working pretty fine with the RPG movement type and the Third Person Cinemachine Camera.
But I need the characters vertical movement relative to the view direction of the camera.

If the player is pressing forward, the character should move forward relative to the camera, and same for backwards, the Character should rotate in the view direction of the camera.
But with Cinemachine Free Look and my setup described above that's not possible or am I missing something?
The character is moving relative to his orientation, not to the camera.

So I would need the general movement and camera behavior of Adventure movement - but the backwards behavior of RPG and the auto run stuff.
Or the Combat movement but with free rotate while standing still maybe?
Is this possible with some default features and settings or do I have dive into some custom scripting? I think I need just an option for the Adventure Movement Profile like "Rotate to camera direction before move", so that the character is first rotating in the view direction and then moving instead of directly moving relative to the camera view direction.

Thank you very much, hope you can help me and there is a not to complex way to achieve this and without breaking any update capability :)
 

Justin

Administrator
Staff member
This is not a feature that is out of the box, but I can add it to my feature request list.

For now what I would do is subclass the Movement Type that is most similar to what you want, which it sounds like is the RPG Movement Type. You can then override the GetDeltaYawRotation method to provide the delta rotation of where the character should move. This method is also good for future updates.
 

DarkLiKally

New member
I will try your suggestion, thanks for the advice!

Maybe this might be useful for other people if they need a free look with actual backwards movement. With or without cinemachine. I think the controller can just benefit from adding this feature as a toggleable option or separate movement set. So feel free to add it to the feature requests.

Anyway, thanks for the fast support!
 

DarkLiKally

New member
Tried it out, working pretty well.

In case someone else is interested in the solution - I just extended RPG third person movement and made a combination of Action, RPG and Combat locomotion sets for the GetDeltaYawRotation method like this:

C#:
namespace Opsive.UltimateCharacterController.ThirdPersonController.Character.MovementTypes
{
    using Opsive.Shared.Game;
    using Opsive.Shared.Events;
    using Opsive.Shared.Input;
    using Opsive.Shared.Utility;
    using Opsive.UltimateCharacterController.Character;
    using Opsive.UltimateCharacterController.Character.MovementTypes;
    using Opsive.UltimateCharacterController.Utility;
    using UnityEngine;

    public class AdventureRPG : RPG
    {
        /// <summary>
        /// Returns the delta yaw rotation of the character.
        /// </summary>
        /// <param name="characterHorizontalMovement">The character's horizontal movement.</param>
        /// <param name="characterForwardMovement">The character's forward movement.</param>
        /// <param name="cameraHorizontalMovement">The camera's horizontal movement.</param>
        /// <param name="cameraVerticalMovement">The camera's vertical movement.</param>
        /// <returns>The delta yaw rotation of the character.</returns>
        public override float GetDeltaYawRotation(float characterHorizontalMovement, float characterForwardMovement, float cameraHorizontalMovement, float cameraVerticalMovement)
        {
#if UNITY_EDITOR
            if (m_LookSource == null)
            {
                Debug.LogError($"Error: There is no look source attached to the character {m_GameObject.name}. Ensure the character has a look source attached. For player characters the look source is the Camera Controller, and AI agents use the Local Look Source.");
                return 0;
            }
#endif
            if (characterHorizontalMovement != 0 || characterForwardMovement != 0)
            {
                var lookRotation = Quaternion.LookRotation(m_LookSource.LookDirection(true), m_CharacterLocomotion.Up);
                // Convert to a local character rotation and then only return the relative y rotation.
                return MathUtility.ClampInnerAngle(MathUtility.InverseTransformQuaternion(m_Transform.rotation, lookRotation).eulerAngles.y);
            }
            return 0;
        }
    }
}
 
Top