In my game I have a power-up that slows everything down. I keep the player at regular speed by dividing deltaTime by timeScale. Everything works perfectly except for OnTriggerStay2D which appears to be affected by the timeScale.

I thought I could just use trigger enter and trigger exit, pushing everything up to the update function that IS running every frame, but those are also slowed down and I'd like to keep things accurate to the player perspective.

So, is there any way to force trigger stay, enter or exit to work in regular time after I've changed Time.timeScale?

  • 1
    \$\begingroup\$ Have you tried using raycast? Not sure but it might not be affected \$\endgroup\$ – Vadim Tatarnikov Jun 6 '16 at 16:39
  • \$\begingroup\$ I have not tried raycasts. I'll give it a try, but a number of colliders can overlap (since I'm using them as triggers) so I'm worried that it will introduce a lot of bugs. \$\endgroup\$ – Califer Jun 6 '16 at 17:01
  • \$\begingroup\$ The overlapping of collider could be solved by adding different layers and then casting more than single raycast, so that each one scans one layer. \$\endgroup\$ – Vadim Tatarnikov Jun 6 '16 at 17:04
  • \$\begingroup\$ Also just a note, fixed update is also being slowed down, however Update() isn't. \$\endgroup\$ – Vadim Tatarnikov Jun 6 '16 at 17:07

The only way I know of to make OnTriggerStay2D get called just as often in real-time when you change the timescale would be to change the physics timestep when you change the timescale. Here's a link with details: http://answers.unity3d.com/questions/24748/altering-fixed-timestep-when-your-game-is-running.html

  • \$\begingroup\$ Thank you! By multiplying my target fixed timestep by the current timescale I was able to make them all work as though time was normal. \$\endgroup\$ – Califer Jun 7 '16 at 17:01
  • \$\begingroup\$ Glad it worked for you. :) \$\endgroup\$ – Cameron Oltmann Jun 8 '16 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.