Forum rules - please read before posting.

Third Person to First Person Toggle

I was curious if you can swap between first and third person views.
I have a third person game going and it's working just as I want. So now I am wanting to add a toggle to switch from third to first after playing a brief animation. My first thought was to do it through player switching.. and just parent the the two together so that the same position and rotation would apply. Then through the action editor have them swap back and forth as needed.
Would this work? If so how can I create a first person character? The character wizard doesn't allow it.

Comments

  • edited January 2023

    Ok kept digging and found that the engine can change the movement method to first person. But I haven't figured out how to activate that camera or do it with a button press.
    I saw another post that mentioned a tutorial and tinpot. I have looked at tinpot and everything is matching. Going through some tutorials now.

  • I'd assume have 2 cameras within the Player gameobject, one over the shoulder and one where the character head is.

    Then trigger an actionlist on button press which switches between the camera and hides the player model when in first person, or just hides the head.

  • A second Player shouldn't be necessary - you'd just need your original Player to be equipped with a First Person Camera that can be enabled at the right time.

    A tutorial on creating such a camera can be found here. The Character Wizard will only create such a camera automatically if the Movement method is set to First Person at the time.

    To then switch between the two, create a Global Boolean variable to keep track of the perspective (e.g. "InFirstPerson").

    To toggle this on and off at the press of a button, create a new input in the InputManager named e.g. PerspectiveToggle, and set its Positive button to something appropriate.

    Next, define a new Active Input via Adventure Creator -> Editors -> Active Inputs Editor. Active Inputs allow you to run ActionLists when a specific input is detected.

    Set the Active Input's Input button to PerspectiveToggle, and click Create to create and assign a new ActionList asset. Set this asset's first Action to a Variable: Check Action that reads the value of InFirstPerson.

    If this variable is True (i.e. the condition is met), have this Action then run a Variable: Set Action to set InFirstPerson to False. If it's False, run a different Action that sets it instead to True.

    As well as changing the variable's value, you'll then want to run an Engine: Manage systems Action to switch the game's Movement method.

    When switching to First Person, AC will automatically switch to the Player's First Person Camera. When switching to third-person (e.g. Direct), however, you'll need to force the camera change with a Camera: Switch Action. This may be best set through scripting for convenience, but test things out with a specific camera for now.

    The main thing to bear in mind at this stage is that changing the Movement method setting actually affects the Settings Manager asset file itself - so such a change will survive exiting Play mode. You'll therefore need to run a separate Engine: Manage systems Action to set this to your intended default value. This can be done via the ActionList on start game field near the top of the Settings Manager.

  • I was so close to figuring this out. I was missing the Cursor additions in the input manager. Thank you.
    1. I hooked up the camera based on the tutorial.
    2. For testing I created a trigger that on enter changes the movement method to First Person.
    3. When I enter the trigger the controls change like they should. However the camera doesn't go into first person until I pause and unpause the game.

  • edited January 2023

    Also as an addendum. When I get into 'first person' Movement method. W,A,S,D all move forward. Unlike the first person prototype that allows strafing walking backwards etc. This I think is caused by rootmotion being enabled in the animator of the character. Is this something that can be toggled and set like movement method?

  • edited January 2023

    Small update. I implemented the button toggle since that works so much faster for testing. A few things I noticed.
    1. When toggling back and forth not only does the first person camera not toggle on as seen above. The Cursor also becomes unlocked from the center of the screen when going back to 'third person'. (I have lock Cursor and Hide Cursor both on through the AC Game Editor).

    Sorry for the multiple posts. I've just had some extra time this morning and decided to get some progress made.

  • edited January 2023
    Ok final set of findings. I used similar logic to do a player switch on button press. As expected I still had to pause and unpause to get into first person not sure what is going on.
    Also, I noticed that when you swap between views regardless of which method used that it can break hot spots if you have ‘place distance hotspots on another layer’ selected. What happens is that when you enter a hot spot after toggling from 1st to third. The hotspot never returns to the default layer.
  • edited January 2023

    Ok so this has been solved.... Kind of.
    I stumbled across it while implementing a way to swap between Hotspot detection types. My third person character was using player vicinity. I wanted my first person to use mouse over.
    In my perspective swap I added a custom action that when movement type = First Person then
    AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.MouseOver;
    and on the flip side when movement type = Direct then
    AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
    I went in to test after making those changes and the switch between Direct and Third Person was instant complete with the camera switching.

    This works well and with an easy variable check I can separate what triggers and hotspots are usable depending on my perspective.

    There are still a few outstanding issues.
    1. In order to bypass the rootmotion for the firstperson camera I did end up using a player switch. Is there any other way to do this?
    2. The Cursor also becomes unlocked from the center of the screen when going back to 'third person'. (I have lock Cursor and Hide Cursor both on through the AC Game Editor).
    3. I noticed that when you swap between views regardless of which method used that it can break hot spots if you have ‘place distance hotspots on another layer’ selected. What happens is that when you enter a hot spot after toggling from 1st to third. The hotspot never returns to the default layer.
    4. This 'fix' does not work if the ActiveInput is set to run in background.
    5. I haven't figured out how to switch to a non 1st person camera without calling it specifically.

    If you want to see the logic I ended with this is it.
    Fix

  • In order to bypass the rootmotion for the firstperson camera I did end up using a player switch. Is there any other way to do this?

    You can amend an Animator's "Root Motion" option through script. For the AC Player, this can be accessed with:

    AC.KickStarter.player.GetAnimator ().applyRootMotion
    

    If you're involving custom Actions, it may be easiest to combine all the custom code upon switching into a single Action.

    1. The Cursor also becomes unlocked from the center of the screen when going back to 'third person'. (I have lock Cursor and Hide Cursor both on through the AC Game Editor).

    This'll be AC's automatic assumption of needs when exiting first-person mode in-game. You can override this, however, by following it up with a Player: Constrain Action that has its Cursor lock set to Enabled.

    I noticed that when you swap between views regardless of which method used that it can break hot spots if you have ‘place distance hotspots on another layer’ selected. What happens is that when you enter a hot spot after toggling from 1st to third. The hotspot never returns to the default layer.

    This may be a bug - I'll attempt a recreation. What is your AC version?

    This 'fix' does not work if the ActiveInput is set to run in background.

    Noted, thank you.

    I haven't figured out how to switch to a non 1st person camera without calling it specifically.

    The switch should occur after exiting a cutscene. If your ActionLists all run in the background, you'll have to use a Camera: Switch Action to force the change.

    If you run this from an ActionList asset and reference the camera in the Player's prefab, however, it'll record and use a Constant ID value so that it should work across all scenes.

  • edited January 2023

    No problem at all.
    Unity: 2022.2.2f1
    AC:1.76.1

    1. Player Constrain did the trick. I tried enabling and disabling through the engine so nice to know where this lives. Thank you.
    2. Using.ApplyRootmotion allowed me swap between movements without doing a player switch. I added it to the custom actions as suggested. Note to anyone else wanting to do this. You will need to add a Character Animate -> Set Standard -> Change Speed Scale make sure that your character moves at the correct speed in both first and direct. (Yes I may have pulled out a stop watch and had my character running sprints while I dialed it in.)
    3. Also, If you have any animation that changes the Y of your character model. (Crouch etc) you will have to account for this in first person. There are a number of ways to do it. I created an empty game object called camera_mount, parented the first person camera to it, attached the moveable script to it, then in the action list for crouch changed the y location for when crouched and not crouched. So now when my character crouches in first or third the camera goes with it.
    4. Camera Switching was solved on a case by case basis. By default it always goes back to the same camera when in direct mode that can then be updated by triggers. For my specific game this works fine. Just means I have to make sure my level design is solid.

    Thank you so much for the advice on this. Your forums/documentation have been a gold mine of best practices.

  • I'm afraid I'm having trouble recreating the "Distant Hotspot" layer issue.

    To be clear: is this occuring when merely switching Movement method, or when switching the Hotspot-detection method.

    I should note that the Default/DistantHotspot layer switching requires a Player with a Hotspot Detector to be present in the scene. Is it possible that this was occuring due to switching to a Player that had no such detector?

  • edited January 2023

    That is possible. It's switching both Movement to first with mouse and then direct with vicinity.
    Let me test it in the new environment where I don't have some of the asset clutter. I'll report back later today.

  • edited January 2023

    Ok test ran
    Here is a video on what is occurring.
    Unity: 2022.2.2f1
    AC:1.76.1
    I only have Adventure Creator, the Morgue Asset and URP installed. Let me know if you need any additional information. For now I am just leaving Distant Hotspot unselected.

    Here is the action list I use to swap between first person and third. The turn on menu at the bottom is just to show the Digital Camera UI in first person. The issue occurs if that section is there or not.
    Perspective Toggle Action List P1
    Perspective Toggle Action List P2

  • Thanks for the details.

    It's because the Default/DistantHotspot layer updating only occurs when using Player Vicinity mode - in the same way that the "Place distant Hotspot" option is only available when this mode is selected.

    To update Hotspot layers manually, run this code within your custom Action that sets the Hotspot detection mode to Mouse Over:

    foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
    {
        if (hotspot.gameObject.layer == LayerMask.NameToLayer (KickStarter.settingsManager.distantHotspotLayer))
        {
            hotspot.gameObject.layer = LayerMask.NameToLayer (KickStarter.settingsManager.hotspotLayer);
        }
    }
    
  • Perfect. Thank you!
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.