Forum rules - please read before posting.

Changing "Constrain Pitch-Rotation" value for First Person Camera in different scenes and more

edited December 2017 in Technical Q&A
Hello Chris, hello all,

I'd like to ask you for help on two issues regarding the "looking direction" of the First Person Camera prefab.

The setup: First Person – Touch Screen – Touch controls Turning Only – Camera 3D

The scenario: the player is exactly in the center of a 360° cylinder surrounding him, so by touching he can "look around". There are Hotspots on the cylinder surface, and when tapped upon, the player shall 
  1. face that particular Hotspot (Player Script: Mecanim –Automatic – Turn before walking)
  2. then move closer to it (Action List: Character Move to Point – Marker to reach – Walk) 
This is working, with one exception: the player is not "looking" towards the Hotspot or the Marker to reach (i.e. slightly up or down), he is just turning his body along the Y-axis. 

My assumption is that I have to tell the Child Camera of the First Person Player to also adjust its pitch-rotation (= raise or lower his head) while the FPP is turning but I am not sure how to do that.


The second thing: I am using the "Constrain Pitch-Rotation" option of the First Person Player's Child Camera with a setting of +/- 13° which is ideal for these 360° scenes, again with one exception, where I would like to limit it to +/- 9° in a special scene. How would I ideally make that change during runtime?

Thanks in advance!

Best, Jensen

Comments

  • You can command the FP camera to tilt up/down (i.e. have the player look up/down) using the Character: Face object Action.  When set to control a First Person player, you'll have an additional option to turn with the head.

    To have a different pitch limitation, you could do it through script - but it's easier to just drop in your Player prefab into the special scene file.  You can then make local changes to that Player, and he'll override the default one (spawned from the Settings Manager) used in all other scenes.
  • Thanks, Chris – cool, I wasn't aware of the option to override my prefab player … superb!

    As regards the first issue, I probably should have been more precise, sorry.
    Yes, the Character: Face object action is part of my action list, too, but what I am trying to achieve is:
    1. face that particular Hotspot (Player Script: Mecanim –Automatic – Turn before walking)
    2. then move closer to it (Action List: Character Move to Point – Marker to reach – Walk) without losing focus. 
    So actually during the whole movement process I'd like to have the object right in the middle of the screen, like in a camera tracking shot. Imagine observing a mosquito at the opposite wall of your room: you get up from your bed and get slowly closer, around the table and the armchair, but your eyes will never lose track of the mosquito …

    I thought of running Character: Move to point and Character: Face object in parallel (with "wait until finished" unchecked) and hoped to continuously adjust the FP's head tilt that way, but that'll prevent both actions from being executed at all (no movement, no facing).

    The closest I could get so far was to:
    1. Character: Face object (incl. FPS head tilt, Face with body, wait until finished)
    2. Character: Move to point (wait until finished)
    3. Character: Face object (incl. FPS head tilt, Face with body, wait until finished) again
    That'll take my FP to the right place and have him look into the right direction in the end … but not while he is on his way there.

    Do you have an idea how I could get this to work? Is there a way for an FP to track an object while being on the move?
  • Nice analogy!

    While the FPS head tilt? option works by affecting the First Person Camera, the spin rotation is handled by the character's root - meaning it will compete for control over the character when walking.  For this reason, it's not possible to use the two simultaneously.

    (For reference, however, the way to get two "Wait until finish" Actions running side-by-side is to precede them with the ActionList: Run in parallel Action)

    In a case like this, where you know where the camera's going to begin and end, it's best to rely on either a series of pre-set cameras (and use the Camera: Switch Action to move between them), or a single GameCamera Animated prefab that's set to play an animation when cut to.

    Is your player constrained within the cylinder the whole time?  It may be easier to rely on camera tricks like this throughout, as the First Person system is really designed for free movement in a more traditional FPS sense.
  • Thanks Chris – that makes sense!

    Actually, the character is not constrained to one cylinder; there are more and they are connected via pathways / corridors, but inside each cylinder there are exactly eight spots only where the player can move towards (but he can freely look around from each of them).

    So you are right: this is not really FP free movement but rather FP on rails, actually a lot like FP movement has been programmed in "The Room". So I will follow your suggestions and play a bit with camera tricks.

    Best, Jens
  • Success! 

    Adding a Moveable Component to the FP and using two Object: Transforms (translate + rotate, move player?: checked) simultaneously does the trick (and looks beautiful, too).

    Which brings me to a new question: is there an easy way to replace "transition time" with "transition speed"? 
    Or to fill "transition time" with a pre-calculated parameter value? 

    The point is: I would like an object transform across a distance of 4 meters to last 4 times as long as one across 1 meter. But for that I would have to pre-calculate the player's distance to the target and dynamically fill the transition time value … so a "transition speed" option woud be much cooler :-)!
  • You could write a custom Action that does this quite easily.  The existing Object: Transform Action is stored in the ActionTransform.cs script file, which you can copy and rename to make your own custom variant of.  In this new copy, you can have the transition time (which will actually become the speed) multiply itself by the distance vector.
  • edited February 2018
    Great, this is working now, too – thanks, Chris!

    There is one final issue I cannot seem to solve: as you can see from the top-down, 
    • we have a simple square room;
    • the green markers show the eight positions the player can reach;
    • clicking on one of the 16 hotspots will take the player to the corresponding marker and have him turn towards the hotspot clicked (technically the markers are just there for illustration purposes; actually the player's target position and rotation comes from two vector3 variables)
    • in the middle of the room there is a collision cube (on the default layer!), supposed to prevent the player from moving in a straight line, but to avoid any center obstacles.
    image

    Infact, though, this collision cube is only serving half of its purpose: it will hide hotspots placed behind it, but it will not prevent the player from passing through it when the action list gets run. So e.g. like in the front-back-screenshot:
    • Hotspot N-S is blocked by the collision cube – good;
    • Hotspot N-N is not blocked by the collision cube – good, too! So player taps on it, and …
    • … action list will pause gameplay (or run background, it doesn't make any difference) and move FP directly and on a straight line right through the collision cube … bad!
    image

    The general setup for the scene is "Touch control turning only, First Person". 

    Now:

    When I change that to "One touch to move and turn, First Person", the collision cube will successfully prevent the FP from passing through it – but only when "touching to move and turn" (= during gameplay)! As soon as I tap the "Hotspot N-N", the action list will behave like before and move the FP right and straight through the collision cube.

    So do I have to assume that this collision cube will not get recognized during the execution of an object transforming action list? 
  • That's correct.  An object being moved with Object: Transform will not account for any other object in its way - it'll just beeline to where its been told.

    That the cube blocks you during gameplay is due to collision and is to be expected.  However, there's no pathfinding involved - you're attempting to move in a direction and the physics system is preventing you from moving through it.

    When it comes to pathfinding, a collider won't change your path like that - you must instead rely on a baked NavMesh.  This is just Unity's standard workflow, as NavMesh baking is handled in Unity's Navigation window.

    AC can be made to calculate correct pathfinding (i.e. rely on a NavMesh) when using the Character: Move to point Action as you first described.  As you hadn't described the need for pathfinding earlier, I suggested the alternatives above.

    You could probably go about implementing canned animations for such situations, but it would be a bit tedious.

    One thing you could try is to have two cameras on the player - one being the default First Person camera, the other being a GameCamera that is set to look at an invisible "Empty" target.  Both cameras at the same position, both immediate children of the player's root.

    Then, when moving across the room:

    1) Snap the GameCamera's target to the Hotspot (Object: Teleport)
    2) Switch to the GameCamera (Camera: Switch)
    3) Move the player via pathfinding (Character: Move to point)
    4) Switch back to the First Person camera (Camera: Switch)

    Haven't tested it myself, and you might find that the First Person camera's orientation isn't correct after switching back, but see if it works otherwise and we'll tweak it.
  • Ok, cool, I am going to play with this concept a bit – 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.