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 bodec · May 26, 2013 at 04:45 PM · c#smoothdamp

how do i smooth out this movement c#

This script is attached to a empty game object and a gun attached to it, on forward movement its very jittery. I am thinking if I can add the line of code to a smoothDamp function it will fix the issue problem I am having is converting a vector3 to a float.

I also tried slerp but not sure what to set the second Quaternion too.

here is the code

     public GameObject cameraObject;
     
     public float smoothSpeedRotation = 0.5f;
     public float holdHeight =  -0.42f;
     public float holdSide = 0.42f;
     //public float holdForward = 0.1f;
     
     float targetXRotation;
     float targetYRotation;
     float targetXRotationVelocity;
     float targetYRotationVelocity;
     
 
     
     // Update is called once per frame
     void Update () {
         
         //effecting the transform of the gun.
         transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0)* new Vector3(holdSide,holdHeight,0));
         
         
         //smothly effect the guns rotation
         targetXRotation = Mathf.SmoothDamp(targetXRotation,cameraObject.GetComponent<MouseLookScript>().rotationX,ref targetXRotationVelocity,smoothSpeedRotation);
         targetYRotation = Mathf.SmoothDamp(targetYRotation,cameraObject.GetComponent<MouseLookScript>().rotationY,ref targetYRotationVelocity,smoothSpeedRotation);
         
         //physically move the gun
         transform.rotation = Quaternion.Euler(targetXRotation,targetYRotation,0);
         
     }
Comment
Add comment · Show 1
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 bodec · May 26, 2013 at 05:04 PM 0
Share

awesome thank you that never even crossed my $$anonymous$$d I forget about LateUpdate If you would either make your answer the answer or change post to answer so I may make it as answered thank you.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by robertbu · May 26, 2013 at 05:01 PM

When dealing with moving object in relationship to a moving camera, jitter problems can usually be fixed by moving the code from Update() to LateUpdate().

Comment
Add comment · Show 2 · 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 robertbu · May 26, 2013 at 05:08 PM 0
Share

I've converted it to an answer. Note I did not answer the separate question about a smoothed rotation. I did not understand the desired behavior (i.e. why you are pulling out only the x and y rotation of the camera). If you can explain, I can perhaps give you code for this as well, or you can open it in a new question.

avatar image bodec · Jun 08, 2013 at 08:23 PM 0
Share

the reason for x and y rotation is spinning around those axes did not want to turn around the z axes the smoothdamp function works great and I rotate the way I am wanting I do thank you for offering more help.

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

13 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Why is Start() from my base class ignored in my sub-class? 4 Answers

Does Scripting Jump exist? (How To use/write goto) 3 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