Scaling gravity by Time.timeScale
Hello,
I'm trying to achieve the QuickSilver effect from X Men Days Of the Future Past, whereas the whole game stays in slow motion and the character moves at normal speed.
Everything is working fine for the character:
float framesPerSecond = 60f;
float scaleVelocity = 1f / Time.timeScale;
character.velocity = new Vector2(velocity.x * framesPerSecond * Time.fixedDeltaTime * scaleVelocity, velocity.y * framesPerSecond * Time.fixedDeltaTime * scaleVelocity);
character.gravity = 1f * Time.fixedDeltaTime * scaleVelocity
The code above makes possible for the character to run freely while in slow motion.
The problem comes to affected objects by slow motion that has force applied to it. e.g: An enemy jumping in slow motion would stop jumping higher because the time was scaled down.
I was trying to fix this by using this code, but the enemy only jumps half of the way.
enemy.gravity = (1f * Time.fixedDeltaTime) / scaleVelocity;
In the code above i'm scaling the gravity down, because I want to make the force to be applied as if it was in normal mode, but it is not working.
I tried to manipulate gravity's value manually and it seems to have this relation:
timeScale = 0.5
gravity ≈ 0.7
===
timeScale = 0.1
gravity ≈ 0.5
Any thoughts of how to solve this?
Thanks!
Your answer
Follow this Question
Related Questions
Do Slowmotion effect for x seconds 1 Answer
Change Time.scale only on specific objects 1 Answer
Animation doesn't switch to default state after setActive 2 Answers
Help ?Can Chronos Reverse Boolean Statement? Help 1 Answer
Edit Gravity for Ramps 0 Answers