Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by okaybj · Sep 18, 2020 at 10:19 PM · first person

how do i smooth between 2 clamps

need to smooth from one clamp to another so the first person cam movement isnt jerky when my player is sliding. have no idea how to do it. heres my code

  if (player.move_forward == true)
          {
              yaw += speedH * Input.GetAxis("Mouse X");
              pitch -= speedV * Input.GetAxis("Mouse Y");
  
              if (player.is_sliding == true)
              {
                  pitch = Mathf.Clamp(pitch, slidingPitchMinMax.x, slidingPitchMinMax.y);
                  yaw = Mathf.Clamp(yaw, yawMinMax.x, yawMinMax.y);
              }
              else 
              {
                  pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
                  yaw = Mathf.Clamp(yaw, yawMinMax.x, yawMinMax.y);
              }
  
              transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
          }

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image N-8-D-e-v · Sep 18, 2020 at 10:47 PM 0
Share

I'm not sure what you're trying to do, maybe $$anonymous$$athf.SmoothDamp is what you're looking for

avatar image okaybj N-8-D-e-v · Sep 18, 2020 at 10:50 PM 0
Share

i have more of a restriction on the pitch clamp when sliding so you cannot look down as much. so if you are looking down when the character starts sliding the camera will snap to the allowed pitch. instead I want it to smooth there

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Magso · Sep 18, 2020 at 11:50 PM

You need to lerp another float value to pitch and set transform.eulerAngles.x to that lerped value like this.

 lerpedPitch = Mathf.Lerp(lerpedPitch, pitch, Time.deltaTime);
 transform.eulerAngles = new Vector3(lerpedPitch, yaw, 0.0f);

Make sure lerpedPitch is declared in the class at the top and not in the function.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image okaybj · Sep 19, 2020 at 01:15 AM 0
Share

Thanks for your help. I tried this with now success but I'm sure I implemented your suggestion wrong. public float speedH = 2.0f; public float speedV = 2.0f;

     private float yaw = 0.0f;
     private float pitch = 0.0f;
 
     public Vector2 yaw$$anonymous$$in$$anonymous$$ax = new Vector2 (-165, 165);
     public Vector2 pitch$$anonymous$$in$$anonymous$$ax = new Vector2 (-85, 35);
 
     public Vector2 slidingPitch$$anonymous$$in$$anonymous$$ax = new Vector2 (-85, -15);
 
     public float lerpedPitch;
 
    
 
     void Update()
     {
 
         if (player.move_forward == true)
         {
             yaw += speedH * Input.GetAxis("$$anonymous$$ouse X");
             pitch -= speedV * Input.GetAxis("$$anonymous$$ouse Y");
 
             if (player.is_sliding == true)
             {
                 lerpedPitch = $$anonymous$$athf.Lerp(lerpedPitch, pitch, Time.deltaTime);
                 transform.eulerAngles = new Vector3(lerpedPitch, yaw, 0.0f);
 
                 pitch = $$anonymous$$athf.Clamp(pitch, slidingPitch$$anonymous$$in$$anonymous$$ax.x, slidingPitch$$anonymous$$in$$anonymous$$ax.y);
                 yaw = $$anonymous$$athf.Clamp(yaw, yaw$$anonymous$$in$$anonymous$$ax.x, yaw$$anonymous$$in$$anonymous$$ax.y);
 
             }
             else 
             {
                 pitch = $$anonymous$$athf.Clamp(pitch, pitch$$anonymous$$in$$anonymous$$ax.x, pitch$$anonymous$$in$$anonymous$$ax.y);
                 yaw = $$anonymous$$athf.Clamp(yaw, yaw$$anonymous$$in$$anonymous$$ax.x, yaw$$anonymous$$in$$anonymous$$ax.y);
             }
 
             transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
         }
     }
avatar image Magso okaybj · Sep 19, 2020 at 02:11 AM 0
Share

The two lines under if (player.is_sliding == true) need to be at the bottom replacing transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);

avatar image okaybj Magso · Sep 19, 2020 at 06:53 AM 0
Share

I see, I tried that but it lerps the mouse position at all times not just at the start of the slide. None the less - thank you for your effort. I am going with a different approach now.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

134 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotating object's xyz-axis but not its mesh 2 Answers

getting out of LookAt messes up first person view 1 Answer

Best way to rotate child and parent game objects in different axes without the rotation going crazy or glitchy? 1 Answer

Multiplayer first person camera 1 Answer

Unity 3D Orienting on Tagged Surfaces / Wall Walking 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges