Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 PZ4_Bailey · Jan 15, 2018 at 02:17 PM · rotationfpsquaternion

How to get smooth object rotation??

Hi, im working on a fps game and i want the camera to smoothly & slightly rotate up when Fire() is called and then smoothly back to start rotation again. The code i have works but not exactly how i want. Can someone please help me? Update() { if(rotationProgress < 1 && rotationProgress >= 0) { rotationProgress += Time.deltaTime * 5; Camera.main.tranform.Rotate = (-rotationProgress,0,0); } } Fire() { rotationProgress = 0; }

Comment
Add comment · Show 4
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 agray427 · Jan 15, 2018 at 05:32 PM 0
Share

How can "if (rotationProgress < 1 && rotationProgress >= 0)" ever be true? You can't both be less than 1 and also greater than 0? I would recommend a lerp function, but you would need to know your destination and how fast you want to get there, but I'm not sure if that is something you know or not. If you clarify this, I can help further!

avatar image PZ4_Bailey agray427 · Jan 16, 2018 at 11:42 AM 0
Share

I dont know lol but somehow it works, the "1" also limits the recoil, if i set it like rotationProgress < 5 then the recoil is much more. But i gave up and just made recoil a animation and its working just the way i want. Thank you for the reply

avatar image Hellium agray427 · Jan 16, 2018 at 11:44 AM 0
Share

@agray427... Well 0.5 is greater than 0 and less than 1....

avatar image Hellium · Jan 16, 2018 at 11:49 AM 0
Share

@PZ4_Bailey : Why don't you use an animation to do so? Or an animation curve like this:

 public AnimationCurve recoilAnimation ;
 private float fireTime ;
 
 Update()
 {
     if( Time.time - fireTime < recoilAnimation.keys[recoilAnimation.length -1].time )
     {
         float angle = recoilAnimation.Evaluate( Time.time - fireTime ) ;
         Camera.main.tranform.Rotate(-angle,0,0);
     }
     // ...
 }
 
 public void Fire()
 {
     fireTime = Time.time ;
    //...
 }


0 Replies

· Add your reply
  • Sort: 

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

127 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

Related Questions

Rotating wrong 0 Answers

Clamp Quaternions Rotation for camera 1 Answer

Gun tilting in the direction you look towards 1 Answer

Gun not rotating with the camera? 1 Answer

Storing camera angles for a FPS -1 Answers


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