Search Unity

Question Transform.Rotate to Vector3.Slerp and Quaternion.Slerp?

Discussion in 'Scripting' started by Bongmo, Mar 6, 2023.

  1. Bongmo

    Bongmo

    Joined:
    Jan 18, 2014
    Posts:
    155
    Hi,

    I got stuck changing the following line (myTransform.Rotate) to Vector3.Slerp and Quaternion.Slerp:

    Code (CSharp):
    1.  
    2.      public float steerAngle = 20;
    3.  
    4.      float steerInput = Input.GetAxis("Horizontal");
    5.  
    6.      myTransform.Rotate(Vector3.up * steerInput * steerAngle * Time.deltaTime);
    7.  
    Any help is appreciated.

    Thanks :)
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    Then you should unstick yourself!!

    Never seen steering code done like that. You might want to review a couple of tutorials for other ways.

    Otherwise, how to report your technical problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried
    - what you expected to happen
    - what actually happened, especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)

    You may edit your post above.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.
     
    Bongmo likes this.
  3. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,998
    I don't see where Lerp or Slerp would go in there. We use them when the final direction is known but we only want to partly turn that way, and stop when we get there. For example, a camera to gradually turning to look at a tree. With steering we don't have a final direction. We just want to turn until they let go of the button and Rotate is fine for that.

    It would be _possible_ to use Lerp or Slerp: create a direction vector aimed far enough in whichever direction they're turning; then use Lerp with a percent computed using the turn speed. But after all that work it would be the same as a simple Rotate.