Forum rules - please read before posting.

fixed camera with movement method - first person

edited January 17 in Technical Q&A

Hello.

I'm working on a 3D character control system where the movement is set to 'Direct - Relative to Camera'. I switch the movement method from 'Direct' to 'First Person' to enable strafing during aiming, and switch it back to 'Direct' when not aiming. Additionally, I have set up fixed cameras throughout the scene, with triggers that switch between them.

However, I'm facing an issue: when the character is in 'First Person' movement mode and I trigger a camera switch, the character immediately moves in the opposite direction instead of continuing in the intended direction until the input is released. I need assistance in resolving this issue so that the character maintains its course during camera transitions, regardless of the movement mode.

Comments

  • If you're just looking to implement strafing - not actual First Person perspective - assign a Transform to the Player's DirectMovementTargetLock property instead.

    Have this be an empty GameObject in the scene that positions itself a set distance away from the Player in the intended direction. Something along the lines of:

    Vector3 direction;
    void Update ()
    {
        if (!isAiming)
        {
            direction = KickStarter.player.TransformForward;
        }
        transform.position = KickStarter.player.transform.position + direction;
    }
    
  • assign a Transform to the Player's DirectMovementTargetLock property instead.

    Have this be an empty GameObject in the scene that positions itself a set distance away from the Player in the intended direction. Something along the lines of:

    Could you clarify more on how to do it. I don't quite get it..

  • If the DirectMovementTargetLock property is assigned, the Player will face it no matter which direction they move when under Direct control.

    You can test this by adding a Cube in the scene and attaching this script to it:

    using UnityEngine;
    using AC;
    
    public class LockPlayerToSelf : MonoBehaviour
    {
    
        void Update ()
        {
            if (KickStarter.player) KickStarter.player.DirectMovementTargetLock = transform;
        }
    
    }
    

    As you're looking to have the Player maintain a fixed direction - rather than focus on a fixed position - you'll need to first record the direction you want to face, and then re-position the assigned Transform to be a set distance away from the Player in that direction. That way, the Player will always be facing the same direction even when locked to the Transform.

    The first script above assumes you have an isAiming bool variable that you're setting to True when in "aim" mode. This is when you'll want to record the relative position between the two, and apply it each frame to set the position.

  • No Chris, what I mean is In 'Direct' mode, when the character walks over a trigger that switches to a different camera, the character continues moving in the same direction unless input direction is changed , which is the desired behavior.

    However, in 'First Person' mode when the character walks over a trigger that switches the camera, the character immediately turns in the direction the new camera is facing, instead of continuing forward. This happens regardless of the player's input - the character turns as soon as the camera switch occurs, and does not maintain the original forward movement until I release the button or choose to change direction. I need a solution to ensure that in 'First Person' mode, like in 'Direct' mode, the character continues moving in the original direction upon camera switch, until the player inputs a change.

  • The "Camera lock snapping" feature is available for Direct movement only, as a it assumes the game is played in third-person.

    Are you actually in "first person" view, or just leveraging the behaviour of First Person's control method? What I was getting at above was an alternative to this.

  • Are you actually in "first person" view, or just leveraging the behaviour of First Person's control method?

    I am in third-person view while leveraging the behavior of first-person control method as a strafing technique. This approach is effective; however, the only issue I encountered is the 'camera snapping' aspect.

  • You're using the mode in a way that's not intended. My advice above has been to do away with that and override the Direct movement facing direction, which is the intended way of overriding the character's facing direction.

    If you wanted to continue with First Person, you'd need to hack AC itself to enable the "Camera lock snapping" in First Person. This would involve updating the PlayerInput script's BeginCameraLockSnap to remove the Direct movement check, i.e.:

    if (Application.isPlaying && !SceneSettings.IsUnity2D () && KickStarter.stateHandler.IsInGameplay () && KickStarter.settingsManager.directMovementType == DirectMovementType.RelativeToCamera)
    
  • edited January 24

    My advice above has been to do away with that and override the Direct movement facing direction, which is the intended way of overriding the character's facing direction.

    I played with it and it turns out your method is indeed the best approach. Thanks Chris.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.