Slow motion on collision.

Would it be possible to make a script telling unity to slow down time when a certain object enters a collider?. Fx. lets say i have a collider around my player and when an object named BulletEnemy enters that collider, time slows down to half speed?

3 Answers

3

Yes. Look up OnTriggerEnter, OnTriggerExit, and Time.timeScale.

I have already looked there but i am horrible at scripting and needed someone to really guide me through it

–

Then LEARN how to write scripts, there are a lot of tutorials.

–

First of all MasterBlaster thanks for the veeeery constructive help. and second, thats exactly what im trying to here.

–

So which bit are you stuck on? First, write an empty OnTriggerEnter function. Check that it gets called when BulletEnemy enters it (just put a simple Debug.Log in). Then, replace the Debug.Log with an assignment of Time.timeScale.

–

ill try that Tanoshimi, though ll probably just fail horrendously.

–

OnTriggerEnter is the correct path as @tanoshimi has stated.

For slowdown. I found this handy little advice online. A very kind soul on the internet gave the answer on here

The gist of it is to add these two lines

   Time.timeScale = 0.5;
   Time.fixedDeltaTime = 0.02F * Time.timeScale;

The fixedDeltaTime is what causes the smoothness to play out. If for whatever reason you need to revert the game back to normal speeds. I apply this after all the calculations are done.

Time.timeScale = 1;
Time.fixedDeltaTime = 0.02F ;

Seems to work for me.

Happy coding and hope this helps others.

Why wouldn’t it be possible?
In your script, however your applying velocity, just reduce it to half if they’re within a certain vicinity of the player.

You’ll most likely want to use an overlapping sphere: Unity - Scripting API: Physics.OverlapSphere

For what i understand you are telling me a way to slow down the bullet right? but i want time slowed down.

–

I figured slowing down the speed of everything would give the illusion of slowing down time, but I wasn't aware of Time.timeScale so that's a much better option. I actually upvoted his answer :)

–