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 Noxury · May 10, 2016 at 04:39 PM · rotationaudiosourceeuleranglesvolumedelta

Accessing delta-rotation values?

Hello,

I have a turret that can rotate around its y-axis. Based on its rotation per frame (delta), it should turn up the volume of an AudioSource which is simulating the rotationsound of the turret.

Basically I need to get the delta-rotY of the turret each frame and handle its volume by this value. I have this so far: (code snippet)

 public Vector3 oldRot;
 void Update(){
     float deltaRotY = Vector3.Angle(tower.localRotation.eulerAngles, oldRot);
     if(deltaRotY != 0)
         audTower.volume = Mathf.Lerp(0, 0.15f, deltaRotY);
     else audTower.volume = 0;
     oldRot = tower.localRotation.eulerAngles;
 }

But this will call always the else part.

Comment
Add comment
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

1 Reply

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

Answer by Eno-Khaon · May 10, 2016 at 05:53 PM

You're not quite using Vector3.Angle() correctly.

Euler angles do not represent the world-space coordinates in which the angle calculation is made. The change to make, however, will be simple.

 float deltaRotY = Vector3.Angle(tower.forward, oldRot);
 // ...
 oldRot = tower.forward;

Get the direction which is currently "forward" for the turret.

That said, there's still a high likelihood that the audio volume won't be consistent. If your framerate ever changes, so will the audio volume, because you're determining volume on a frame-by-frame basis.

If possible, it may be better to determine the rate at which the turret is turning (i.e. degrees/radians per second) and adjust the volume based on that instead. A rotation speed can be consistent with a variable framerate. The distance rotated per frame should not be.

Comment
Add comment · Show 1 · 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 Noxury · May 10, 2016 at 06:20 PM 0
Share

@$$anonymous$$o $$anonymous$$haon Thank you! I have done a workaround for the issue you have pointed out that the audio volume will not be consistent by calling this in FixedUpdate, although this is not suitable for using non-physic-based calculations.

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

51 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

Related Questions

Problems caused by non-unique Euler angle solutions 1 Answer

How to get Angle float of specific axis.(Turret clamping related). 2 Answers

Instantiating an object in front of the player 3 Answers

When applying a 90 degree rotation to Euler Angles, it is over/undershooting sometimes.. 2 Answers

Camera Zoom from rotation. 0 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