Forum rules - please read before posting.

First person rotate player 180 degrees

Hello everyone, i made a custom player controller for my first person full body project, and i would like to rotate player 180 degrees using custom script but it makes the rotation and instantly turn back again in mouse direction, i've tried already a few different ways but no results, what would be the best approach to rotate player smoothly even in first person? Scripting suggestions are well accepted.

Many thanks :D

Comments

  • Is AC involved with this motion at all (i.e. using AC's First Person movement / camera modes), or is it all (camera rotation included) handled with your custom script?

    AC's free-aiming first-person mode invovles turning the camera up/down, while turning the player root left/right. If you turn the player manually through script, you probably need to apply the rotation (as a quaternion) to the Player script with:

    AC.KickStarter.player.SetRotation (newRotation);
    
  • Hi Chris, my custom script is made to add crouch, player 180 degrees rotation and disable input, while basic player movement and camera movement are managed by AC player script. Thank you :smile:

  • Ok, i did another try, but no results, or better, player turn itself but if the players start is rotate by 80 (example) it will rotate till y 180.
    I share my script, is someone want to help me would be awesome.

    thanks again :smile:

    https://pastebin.com/LFK6FqkN

  • You do not need to modify the transform rotation - calling SetRotation will handle that:

    Quaternion newRotation = Quaternion.Lerp(acPlayer.transform.rotation, playerAngle_180, 0.1f);
    acPlayer.SetRotation (newRotation);
    

    Be aware, though, that since you're lerping the angles this would need to be called for every frame of the rotation - not just the moment that the input button is first pressed.

  • Not working yet, player still not doing a full 180 degree rotation but just rotating to y 180, so if the player is on y 90 it will rotate just 90 degrees. Do you think can be possible to rotate 180 degrees using another method like animation or so? the right script must let the player rotate using his animation but i did a few try using a few 180 rotation animations got from mixamo and trying apply or not rootmotion, with no success. Or try to simulate an "auto movement" of the mouse, i dunno how can i get around the problem.

  • You're attempting to turn to a pre-defined vector, stored as the variable "playerAngle_180" in your script. This is in world-space co-ordinates, not relative to the direction your player is actually facing at the time you want to turn.

    For that, you'd have to create a new vector at the moment you want to turn. This would typically be just the inverse of the player's forward direction, i.e.:

    -transform.forward
    

    This isn't related to AC, however, but should be common enough to find examples of in the Unity forums.

  • all right Chris, thank you for your help, really appreciate it :smiley:

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.