Search Unity

180 degree player "quickturn"

Discussion in 'Scripting' started by DoctorEditor, Jan 16, 2019.

  1. DoctorEditor

    DoctorEditor

    Joined:
    Jan 16, 2019
    Posts:
    2
    So, i want to make a "psx survival horror game", and i need to make a quickturn button, that makes the player rotate 180 degrees smoothly, but i can't figure out how to add this to my "walk" script, i already tried something, but doesn't works. Here's the "quickturn" lines:
    Code (CSharp):
    1. if (Input.GetButton ("Quickturn")) {
    2.             Vector3 smoothedRotation = Vector3.Lerp (transform.rotation, desiredAngle, quickTurnSpeed * Time.deltaTime);
    3.             transform.rotation = smoothedRotation;
    4.         }
    5.  
    "desiredAngle" need to be current player rotation + 180 degrees, ... i guess.

    Also, sorry for the poor writing, i'm brazilian and obviously english aren't my primary language.

    Edit #1: I've looking similar scripts, and i've wrote this:
    Code (CSharp):
    1. if (Input.GetButton ("Quickturn")) {
    2.             rotation.y = transform.eulerAngles.y;
    3.             transform.Rotate = Vector3.Lerp(rotation, rotationSet, quickTurnSpeed * Time.deltaTime);
    But, i still getting a error "The left-hand side of an assignment must be a variable, a property or an indexer", i can't figure out what's going on...
     
    Last edited: Jan 16, 2019
  2. If you would read the manual...
    https://docs.unity3d.com/ScriptReference/Transform.Rotate.html

    You would know that Rotate is a method, so you need to call it, not assigning value to it. Please visit the link, there is an example there.
     
  3. DoctorEditor

    DoctorEditor

    Joined:
    Jan 16, 2019
    Posts:
    2
    I've managed to do it in another way, but now i can't turn the player whatever angle i want.
    Code (CSharp):
    1.     void Update (){
    2.         if (Input.GetButton ("Right")) {
    3.             transform.Rotate (Vector3.up, Time.deltaTime * rotSpeed);
    4.         } else if (Input.GetButton ("Left")) {
    5.             transform.Rotate (-Vector3.up, Time.deltaTime * rotSpeed);
    6.         } else if (Input.GetButton ("Quickturn")) {
    7.                 targetAngle.y += 180f;
    8.             }
    9.             currentAngle = transform.eulerAngles;
    10.             currentAngle.y = Mathf.LerpAngle(currentAngle.y, targetAngle.y, lerpTime * Time.deltaTime);
    11.             transform.eulerAngles = currentAngle;
    12.  
    13.         if (Input.GetButton ("Up")) {
    14.             transform.Translate (Vector3.forward * Time.deltaTime * playerSpeed);
    15.  
    16.         }else if (Input.GetButton ("Down")) {
    17.             transform.Translate (-Vector3.forward * Time.deltaTime * playerSpeed);
    18.         }
    19.     }
    (Also, sorry for still making mistakes like this, I have not been programming for a long time, I'm still a beginner).