2
\$\begingroup\$

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?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Have you tried using raycast? Not sure but it might not be affected \$\endgroup\$
    – John Smith
    Jun 6, 2016 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, 2016 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\$
    – John Smith
    Jun 6, 2016 at 17:04
  • \$\begingroup\$ Also just a note, fixed update is also being slowed down, however Update() isn't. \$\endgroup\$
    – John Smith
    Jun 6, 2016 at 17:07

1 Answer 1

3
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\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, 2016 at 17:01
  • \$\begingroup\$ Glad it worked for you. :) \$\endgroup\$ Jun 8, 2016 at 19:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .