Forum rules - please read before posting.

Limiting First Person look (Yaw)

Hey Chris,

Been looking into limiting the players yaw to a certain radius when in first person for conversations and certain scenarios.

Delving into the code on the first person camera, it notes the yaw control is controlled in the player script. Is this correct? Just making sure before I start looking how to customise it.

Trying to avoid writing a completely new motion controller as the supplied one is pretty much perfect except for limiting yaw and possibly jumping

Comments

  • edited August 2020

    The yaw is determined by the Player's facing direction, yes. When you look left and right, you're essentially just turning the Player.

    If you wanted to limit the yaw, you'd have to also limit the Player. A custom script that reads the Player's angle and sets it to a constrained value by calling SetRotation in LateUpdate should do it.

    Alternatively, you could temporarily set the Player's Motion control field to Manual, so that you then have total control over the Player's rotation through script.

  • edited August 2020

    Feel silly now that I found today theres something is written with pretty much exactly what I want to do! Haha

    https://adventure-creator.fandom.com/wiki/Camera_-_Constrained_first-person

    Although I did take a punt at trying to write something myself. I managed to get the players angle, but I was not able to trigger setRotation

    I kept getting the error
    An object reference is required for the non-static field, method, or property unity

    I believe I am just not writing it out AC.Char.SetRotation(maxRotationY); Correctly.
    What is the correct way to call it? I am still pretty fresh to learning coding, so I'm struggling to figure out how to us AC commands. Never sure to use Kickstarter. or otherwise.

    public static GameObject clampedPlayer;
    public float minRotationY = 20;
    public float maxRotationY = 90;
    public float c_Rotation;
    
    
    
    // Update is called once per frame
    void LateUpdate()
    {
    
    
        c_Rotation = clampedPlayer.transform.rotation.eulerAngles.y;
        if (c_Rotation >= maxRotationY)
        {
            SetRotation();
        }
    }
    void SetRotation()
    {
        AC.Char.SetRotation(maxRotationY);
    
    }
    

    }

    Code works except for the AC command

  • AC.Char is a class - not a reference to the class instance, i.e. the character themselves.

    The Player character can be accessed with:

    AC.KickStarter.player
    

    So the equivalent would be:

    AC.KickStarter.player.SetRotation (maxRotationY);
    
  • Thank you, works perfectly!

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.