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 Briosh · Mar 06, 2011 at 12:29 PM · iosiphonemathframeratecalculate

Different calculations/math results between Unity editor and iPhone ?

I couldn't think of a way to put it better and also, i couldn't find any specific answers on the web so i am asking if some else has run into the same problem.

I am developing a game where the enemies absorb energy from the player. Depending on their distance the absorb rate varies from a min to max.

Now, I have this strange issue when testing the game: In the editor (or when building for Web/Mac) everything runs fine. The enemies absorb energy as expected.

When running the iPhone build though (in an iPhone 4G, iOS 4.2), most enemies completely drain the player's energy in less than a second (sometimes instantly!).

I assume that it has something to do with frame drops or frame-skips but i get 20-25 fps average (which isn't bad right?) Also, since calculating everything with * Time.deltaTime this shouldb't be an issue -theoretically-.

I even tried locking the framerate but to no result.

The code I'm using for the above is as follows: The distance between an enemy and the player is calculated by the enemy inside the Update function using:

function Update(){

 distance = Vector3.Distance(playerObject.transform.position, transform.position);

 //where playerObject is obviously the player.
 //some other code here...
 //Then the script calls the absorb function

 if ( distance < minDistance ){
     Absorb();
 }

 private function Absorb(){
     if ( ! dead ){      
         //Charge
         if ( energy < energyNeeded){
             var tmpStealRate:float = (stealRate / (distance/2)) * Time.deltaTime * 100 ;
             energy += tmpStealRate;
             //Attract particles
             playerParticlesHolder.LookAt(transform);
             player.loseEnergy(tmpStealRate);
         }
     }
 }

The above code is in the same script. The loseEnergy function in the player script is as follows

public function loseEnergy(lossRate: float){
    if ( Time.timeScale != 0 ){
        if ( energy >= 0.0 ){
            energy -= lossRate * Time.deltaTime * 100 ;
            updateParticles();
            draining = true;
        }
        else {  
            GetComponentInChildren.<ParticleEmitter>().emit = false;
            GameOver();
        }
    }
}

EVERY script in the game uses Update function. There is not one single FixedUpdate in the game.

Also, using the profiler in unity and the xcode instruments, i see no more than 15-20% CPU usage which is way too low to assume that there are continues frame-skips/drops.

(btw, I use deltaTime * 100 because it helps me using float values in the inspector. i.e. the stealRate on most enemies is 0.3 ( which should be 30 per second ingame) )

Comment
Add comment · Show 2
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 yoyo · Mar 06, 2011 at 07:42 PM 0
Share

tmpS$$anonymous$$lRate has already been multiplied by Time.deltaTime * 100, then you multiply again inside loseEnergy, which seems wrong ... but doesn't explain why results are different on the iphone.

avatar image Briosh · Mar 08, 2011 at 08:57 AM 0
Share

yes thats probably bad thank you, i removed it but still, i don't get why it produces different results in iOS. I am afraid it has something to do with 'spikes' or sudden frameskips. Using fixedUpdate by the way, would be a bad idea for iPhone ?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by user-11329 (google) · Apr 08, 2011 at 05:21 PM

I'm having the same problem with some very simple code. I'm updating a velocity value with acceleration*Time.deltaTime. In the editor preview it works as expected but on IPhone the velocity just increases to infinity. I'm still looking into the problem but it's a strange one.

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 Briosh · Apr 09, 2011 at 07:27 AM 0
Share

after optimising more and more, my problem eventually disappeared. So, now i quite sure that it had to do with the low frame rate.

How many FPS are you getting? Is your average fps above a certain number, or it drops instantly now and then?

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

No one has followed this question yet.

Related Questions

Low FPS rate. Can't find the problem. Followed Unity's Guide 2 Answers

How do I get high smooth FPS in Unity??(Improve Fillrate) 1 Answer

Is there a way to create applications that run on fixed frame rate of 60fps on iOS? 1 Answer

iPhone Resolution Screen Switch 0 Answers

Mini Mac - Can this Compile Unity? 2 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