Search Unity

where/how set fixedDeltaTime independent of FixedUpdate()'s rate?

Discussion in 'Physics' started by Deeeds, Apr 16, 2018.

  1. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    I thought I said that doesn't have a yes or no answer. Why are you asking me this again? I believe I am unable to help you at this point.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    Actually, let's do this:

    Let me ask you questions rather than you ask me. That way I can direct my answers better.

    Please show me your script that is calling manual simulation at 240Hz. I can guarantee it's not being called at 240Hz but instead you're simply calling it via FixedUpdate/Update at 60Hz but passing in a duration to simulate for, not a frequency of it being called.

    As I said above, before each Physics2D.Simulate call returns, you get Trigger/Collision callbacks.
     
  3. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    Let's use your example of four calls to Simulate in a row,

    Code (CSharp):
    1.  
    2. FixedUpdate(){
    3. simulate(1/240th)
    4. simulate(1/240th)
    5. simulate(1/240th)
    6. simulate(1/240th)
    7. }
    I'm using a while loop with incrementation for the rate I want and a divisor, but that's so I can flex for faster and slower, and shouldn't be making any difference to the above.

    Using the above, can you explain when Collision/Trigger callbacks are made during this single FixedUpdate if, for example, an object is in OnTriggerStay state during each of the 4 simulate calls?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    So this is part of the miscommunication. You're not calling the "Physics2D.Simulate()" at 240Hz at all. You're calling it at 60Hz via FixedUpdate (you said this was 60Hz) and telling it to simulate the objects for 1/240th of a second. That is a huge difference.

    So I'll repeat my answer: You'll get collision/trigger callbacks after each Physics2D.Simulate. In your example, it'll happen four times.
     
  5. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    Is it possible to call AND simulate Simulate() at 240Hz whilst FixedUpdate() and Update() are at 60Hz?

    Just a yes or no will be fine.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    I cannot help you if you continue to try to restrict me to yes or no when I do not even understand your questions.
     
  7. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    I've come to the conclusion that you're German, or an expert in C++. Or both.

    No offence is meant. This is a designer's view point of programmers, communication and languages.
     
  8. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    I've enlisted the help of @Gregoryl to see if we can find a common language with which to discuss this. Part of the reason I'm so thrilled with your work on the 2D physics engine pertains to how I'm using Cinemachine to track my game's hero. I can understand his version of programmer-speak. Hopefully you and he can understand each other and we can resolve this, and make the most of what's possible between a designer, a camera programmer and a C++ programmer ;)
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    I'm not even sure what that means. I'm English and live in the UK. I implemented the 2D physics system here at Unity so you're talking to the correct person however you've already indicated previously that you're new to Unity and you don't know C# very well at all which is fine but you're also not listening to my advice unfortunately.

    I am having to interpret what you're saying when you're asking things that are clear to you but are not clear in real implementation terms to me. It's also really evident that you desperately need to do some basic tutorials to help you get grounded and I hope you do that.

    Unfortunately I am not sure how I can help you further.
     
    Last edited: Apr 18, 2018
    Deleted User likes this.
  10. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    I hope @Gregoryl can help you see I'm not quite as clueless as you seem to think I am. I tend to think the problem is much more an issue of terminology and language, lexicon, crosstalk over differing conceptualisations and a lack of shared contexts than one of capability.

    We share a language, but not how we use it.

    We are planets apart. NO doubts about that. The greatest gap between humans is from experts in C++ to those of us blessed with visual thinking ;)

    I'm pretty sure your allergy to Yes and No doesn't help, either...
     
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    You are putting words in my mouth again. I have been trying to highlight when your questions made no sense i.e. there wasn't a yes or no answer.

    It's clear that despite my best efforts, I am unable to help you. I hope you find your yes/no answers though. ;)

    Good luck with your project.
     
    Deleted User likes this.
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Well that was a painful read. I don't really want to get mixed up in this discussion but I will venture to offer the following observation.

    I think @Deeds is not grasping a key point that @MelvMay is taking for granted: "Game Time" and "Real-Life Time" are two completely different things. @Deeds wants a guarantee of 240 Hz in real-life time, and doesn't understand how the code samples provided can give him that. Answer: they can't. Calls to Simulate() are just sequentially advancing the physics system's internal clock by deltaTime. That clock bears no relation to real-life time. There is no way to synchronize them perfectly all the time.

    The game does not run at a fixed frame rate. The exact frame rate depends on all kinds of things beyond Unity's control, including what the operating system is doing in the background. Update() is called with the current frame rate - which is variable. Variable framerates are not good for many kinds of simulations (e.g. physics), which require fixed framerates.

    Therefore, for each frame (of variable time), FixedUpdate will be called as many times as its fixed timestep will fit within that time. This is to advance the physics game clock to keep as much as possible in line with the real clock at the end of the frame. So the physics clock gets advanced, from a real-world point of view, in fits and starts. From its own (internal) point of view, it is running perfectly smoothly.

    @Deeeds does that make sense?
     
  13. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    Yes, makes sense, and I know most of this.

    The question is this:

    If I force Simulate to happen 4x for each FixedUpdate (or update, both at 60Hz, I don't care where Simulate is called 4x for this question), do 4 lots of Collision/Trigger events get called DURING that FixedUpdate?

    Does Simulate(happening 4x during an update) cause 4 calls to Collision and Trigger callbacks if they're happening during this time?
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    yes and yes
     
    Deeeds likes this.
  15. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    THANK YOU!!!!

    That's what I thought. I'm sorry if my way of asking wasn't clear. 4x60Hz = 240Hz... I used Hz as an indicator of frequency instead of FPS... probably should have said something else that might be less likely to be construed as exactly 1/240th of a second, but happening 240x per second.

    DOH!!!!
     
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    Glad you got your answer but I hope you also see I said:

    Good luck!
     
    romi-fauzi likes this.