Forum rules - please read before posting.

Make Player camera adopt rotation values

Hi,

I'm making a game with a first person camera and I'm trying to do a seamless camera switch that will eventually be the player's new point of view in position and rotation. I'm having trouble making the player camera adopt the new camera's rotation. I have the position figured out. Here's how I set it up:

-Player triggers an event and I use Camera: Switch to go to the new point of view.

-I then use Object: Teleport to teleport the Player to the position where the new camera is.

-This is where I get stuck. If I use Camera: Return to last gameplay, the camera rotation values goes back to what it was before the teleport which is undesirable. I've tried Character: Face Object and Face Direction, but it's imprecise. Also tried Object: Transform on the Player and Object:Transform - Rotation on the FP camera, but it just resets back to the old rotation values after the action runs.

Does anyone know if there's a way to make the FP camera adopt specific rotation values without resetting or is there a way to use the camera I switched to as my new player camera?

Thanks,
Jason

Comments

  • The Character: Face object Action includes an FPS head-tilt? option that'll allow you to look up/down at a given object.  If that isn't sufficient, you can implement a simple custom script to do the job.

    First understand that the FPS camera controls pitch rotations only (i.e. local X axis).  Spin (global Y axis) rotations are handled by the player's root.

    The MainCamera has a special function that returns its forward rotation without accounting for pitch.  This can be applied to the Player with:

    Quaternion playerRotation = Quaternion.LookRotation (KickStarter.mainCamera.ForwardVector);
    KickStarter.player.SetRotation (playerRotation);

    The FirstPersonCamera can have its pitch value set directly:

    float pitchAngle = KickStarter.mainCamera.transform.localEulerAngles.x;
    KickStarter.player.FirstPersonCamera.SetTilt (pitchAngle);

    This code can be placed in a custom script and triggered via the Object: Send message or Object: Call event Actions, or placed in a custom Action.
  • Many thanks, Chris! Will give this a try.
  • Just now getting around to using this and am getting an error when I set the pitch value of the FirstPersonCamera.

    I'm just using it in a custom Action.

    override public float Run ()
            {                   
                float pitchAngle = KickStarter.mainCamera.transform.localEulerAngles.x;
                KickStarter.player.FirstPersonCamera.SetTilt (pitchAngle);
                return 0f;          
            }
    

    And the error I get is this:
    error CS1061: Type UnityEngine.Transform' does not contain a definition for SetTilt and no extension method SetTilt of type UnityEngine.Transform' could be found. Are you missing an assembly reference?

    Any idea why I might be getting this error? Thanks.

  • Apologies - it's SetPitch, not SetTilt.

  • Hmm, it doesn't seem to like SetPitch either since it still throws the same error:

    error CS1061: Type UnityEngine.Transform does not contain a definition for SetPitch and no extension method SetPitch of type UnityEngine.Transform could be found. Are you missing an assembly reference?

  • KickStarter.player.FirstPersonCamera.GetComponent <FirstPersonCamera>().SetPitch (pitchAngle);
    
  • Thanks, Chris! Got it working.

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.