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 /
  • Help Room /
avatar image
0
Question by jason416 · Dec 17, 2019 at 03:01 AM · velocityaccelerationconstraints

How to calculate acceleration and velocity of constrained objects

I'm stuck on trying to build a manual accelerometer/speedometer script for objects that are using ParentConstraint component to move around (no RigidBody)

I'm running into issues with the acceleration part, with the numbers jumping around wildly, I suspect it is something related to Update vs Fixed Update, and/or Time.deltaTime vs fixedDeltaTime. Or maybe I just need to average over more frames? Or maybe my math is messed up...

Here's sorta what I have so far, any help would be amazing.

         void Update()
         {
            /////////////  VELOCITY  ////////////
             Velocity = (currentPosition - prevPosition) / Time.fixedUnscaledDeltaTime;
             CurrentSpeedAvg = ( Mathf.Abs(Velocity.x ) + Mathf.Abs(Velocity.z) ) / 2 ; 
             //This part seems to work fine, I'm getting the average velocity of x and z axis.


             /////////////  ACCELERATION ////////////////
             CurrentAcceleration = (Velocity - prevVelocity) / Time.fixedUnscaledDeltaTime;
             CurrentAccelerationCoef = ((Mathf.Abs(CurrentAccelerationLocal.x) + Mathf.Abs(CurrentAccelerationLocal.z)) / 2); // this jumps around wildly
            
             CurrentAccelerationSmoothed = Mathf.Lerp(CurrentAccelerationCoef, pastAccelerationCoef, .5f);  //Here I was just attempting to smooth it out but it's still unusable

            ////////////////  STORED FOR NEXT FRAME   //////////////
             prevPosition = currentPosition;
             prevVelocity = Velocity;
             pastAccelerationCoef = CurrentAccelerationCoef;
         }
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
0

Answer by jason416 · Dec 19, 2019 at 06:33 PM

So I was able to get some usable data by doing pretty heavy filtering using an animation curve and mathF.smoothDamp (smoothDamp seems much better for this than Lerp)

But I still think the initial calculation isn't being done right because there's so much noise in the calculation. If anyone has a better solution please share.

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 luqiang21 · May 11, 2020 at 11:02 PM 0
Share

In your question, what is CurrentAccelerationLocal? Is it equal to CurrentAcceleration? And what is the meaning of CurrentAccelerationCoef? Should you square x and z values from CurrentAcceleration?

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

191 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

How to get static speed 1 Answer

Rigidbody. Acceleration of free falling object works bad 0 Answers

Acceleration/Deceleration on a Rigidbody2D 0 Answers

Figuring out what the acceleration will be before applying force to RigidBody2D 0 Answers

in projectiles, how to equate horizontal speed as function of Horizontal displacement(how far I want the object to travel sideways) 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