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 baris150490 · Dec 28, 2013 at 11:11 AM · mathfformulamagic

Is there a Magic Code for getting delta values?

Hey, i am wondering that if there is any magic code or function that gets the delta of any floating value between last and current frame? Like a Mathf but doing a compare job between frames.What would be the ways of doing it?Any magic formula for this?I know that Time.deltaTime is irrelevant depending on the fps and gets always the same value.So could we do a math over it? If we multiply a floating value with Time.deltaTime would it give a kind of delta for us?

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
1

Answer by KellyThomas · Dec 28, 2013 at 11:15 AM

No magic formula, just manual tracking:

 float lastFrameValue;

 void Update() {
     float deltaValue = currentFrameValue - lastFrameValue;
     //other stuff
     lastFrameValue = currentFrameValue;
 }  

Wash, rinse, repeat.

You could build a system that took an ID and current value pair, then returned the delta but it's not part of the unity API and it would be slower to execute than using the pattern above.

Comment
Add comment · Show 7 · 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 baris150490 · Dec 28, 2013 at 11:24 AM 0
Share

I am using the code above as well but i am not satisfied with it is there any alternative to that please?

avatar image baris150490 · Dec 28, 2013 at 11:46 AM 0
Share

here is why i am not satisfied with it..

alt text

untitled.png (106.9 kB)
avatar image baris150490 · Dec 28, 2013 at 11:47 AM 0
Share

here is also the code;

 #pragma strict
 var target : Transform;
 var oldAngle : float;
 var newAngle : float;
 var angle : float;
 oldAngle = $$anonymous$$athf.Atan2((target.position - transform.position).x, (target.position - transform.position).z) * $$anonymous$$athf.Rad2Deg;
 
 function Update ()
 {
      if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.A))
      {
      target.RotateAround(Vector3.zero, Vector3.up, 5);
      }
      else
      {
      target.RotateAround(Vector3.zero, Vector3.up, -5);
      }
 newAngle = $$anonymous$$athf.Atan2((target.position - transform.position).x, (target.position - transform.position).z) * $$anonymous$$athf.Rad2Deg;
 angle = newAngle - oldAngle;
 oldAngle = newAngle;
 Debug.Log(angle);
 }

As well as angle won't increase correctly, it does increase to 270 then all in sudden change to -90, i don't know why.

avatar image KellyThomas · Dec 28, 2013 at 12:15 PM 1
Share

Ok then, the problem isn't tracking deltas between floats. The problem is dealing with a "wrapped" number space i.e. 360 = 0, 359 = -1.

avatar image KellyThomas · Dec 28, 2013 at 05:13 PM 0
Share

In your code above, please try replacing Debug.Log(angle); with:

 Debug.Log("old: " + oldAngle + ", new: " + newAngle + ",delta: " + angle);

You will see why the numbers behave like they do.

One useful trick is to normalize them to the range -180 to 180.

This ensures that we have the smallest angle between the other two angles.

Show more comments

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

20 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

Related Questions

mathf.sin((Mathf.PI / 180) * 180) get 0.8966.. 2 Answers

Distance in a Trajectory of a projectile 0 Answers

Wispy magic effect 0 Answers

LineRenderer: 2D Parabola in 3D Space 1 Answer

Mathf iphone input 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