- Home /
Changing the objects rather than time.
On my game I have a time gate. When you walk through it time slows down. The character also slows down. How do I change it so that everything slows down except the main character so I can do some pretty epic things. The timegate is a box with a trigger. Here is the script applied to the timegate:
function OnTriggerEnter () {
if (Time.timeScale == 1.0){
Time.timeScale = 0.3;
}
}
Answer by Anxo · Jan 28, 2013 at 12:30 AM
You can accomplish this by not changing the time but the speed at which everything else moves. You can have a global variable called myTime or what ever and you can multiply all your animation speed and or animating objects and particle speeds by this number (1 by default) then when you enter the time gate you change the global myTime variable to 0.5 and everything will slow except for your main character.
Answer by aldonaletto · Jan 28, 2013 at 01:42 AM
That's a complicated job, because everything is affected by timeScale. In many cases, however, you can compensate the modified Time.timeScale with a different Time.deltaTime value: calculate the new value by dividing Time.deltaTime by Time.timeScale. In the traditional CharacterController.Move example, for instance, you can modify the last lines (the ones that use Time.deltaTime) like this:
...
// add this line to calculate the modified deltaTime:
var newDeltaTime = Time.deltaTime / Time.timeScale;
// Apply gravity
moveDirection.y -= gravity * newDeltaTime;
// Move the controller
controller.Move(moveDirection * newDeltaTime);
}
If you're using the First Person Controller prefab, modify the Move example like above, save it as FPSWalker.js and add it to the character, then remove the scripts CharacterMove.js and FPSInputController.js
Your answer
Follow this Question
Related Questions
Simulate gravity on rigidbody 1 Answer
Good old trig and NaN 1 Answer
What's the Rigidbody's gravity unit? 1 Answer
Animations ignore TimeScale 8 Answers
Trigger with Gravity + Collision 2 Answers