- Home /
Velocity and Time.scaleTime
Hi,
I'm trying to create a canon that throws grenades. each grenade has a rigidbody and to shoot them I just do
bullet.rigidbody.velocity = new Vector3 (1f, 1f, 0f) * speed;
But the thing is that my game has a slow time logic which makes the grenades slow too. I want the whole game to slowdown, except the grandes!!
In other words I want this line
bullet.rigidbody.velocity = new Vector3 (1f, 1f, 0f) * speed;
to be not affected by the time.ScaleTime
I have created a project in github here if you want a base to test:
https://github.com/tzamora/VelocityVsScaleTime
and here is a package to import
https://dl.dropboxusercontent.com/u/4426771/VelocityVsScaleTime.unitypackage
What people tell me is that I can't touch the underneath timeScale that affects the velocity of the rigidbody.
If somebody can confirm me this It would very helpful
If not then, hey, how could I throw a grenade and not be affected with my slow time logic. how can I reproduce this effect without velocity? If I use addForce my speed is not constant it keeps just increasing and increasing, I want as when using velocity a constant movement in the object. So is there a way to do the velocity manually, should I draw a curve outline and make the grenade follow it?
What is the best approach? Thanks :)
Can you not increase its velocity by the inverse of the time scale reduction?
Answer by Baste · Oct 31, 2014 at 12:49 PM
bullet.rigidbody.velocity = new Vector3 (1f, 1f, 0f) * speed * (Time.timeScale / 1f);
Exactly what @MrSoad suggested.
Ok I have already tried this and tested in this commit: http://goo.gl/AUz7PB
First I tested with speed (Time.timeScale / 1f); but it didnt quite work it, but then I change it to speed (1f / Time.timeScale);
It quite worked, but as you can see here (I dont know if it will work)
https://dl.dropboxusercontent.com/u/4426771/vevs/vevs/vevs.html
the ball just don thave that grenade'ish efect, its not parabolic.
Thanks.
Answer by Mathieu_Dossmann · Oct 31, 2014 at 01:40 PM
Here's some informations to clarify your problem :
Defining a velocity to a rigidbody and then multiply it by a speed is a bit of nonsense, because Velocity is the speed of an object (meter/s or unit/s usually).
When using a rigidbody and initializing some values like Velocity, the unity physics engine will proceed some calculation depending on different factors applied to the object : the gravity, friction, angular drag and so on, based on a Time.fixedDeltatTime "linked" with FixedUpdate() calls.
If you modify TimeScale, it will affect also every values of the class Time except Time.realtimeSinceStartup. And it's logical because you need to match what's display and what's processed. The deltaTime for displaying (Update()) a image is NOT affected by TimeScale, only the physics (FixedUpdate()). That's why modifying TimeScale will also affect the physics components and procesing.
The parabol of a object moving is directly linked to it's velocity, aerodynamism (air friction), acceleration and the global gravity. This is automatically processed by Unity as already told. If you want to "move" the object yourself, you'll need to check the Kinetic option in rigidbody component.
So as proposed by Tzamora, you could use the inverse of TimeScale but with also :
Velocity * Time.deltaTime * (1/TimeScale)
to keep the velocity constant if theTimeScale is modified.
If TimeScale < 1 , the grenade velocity will appear faster than the rest of the objects. If TimeScale > 1, the grenade will appear slower than the rest of the objects.
With Kinetic movement, you'll have to update the position of the grenade yourself, involving Trajectory Parabolic Movement.
Hi, I tried to change the code with Velocity Time.deltaTime (1/TimeScale) but it didnt quite worked. It throws the ball in a more linear way
As you said, maybe, there are other variables that the physics engine is altering, maybe drag?
You can see the changes of my code here http://goo.gl/W60nXA
Did you try to modify Gravity as well? Because if you dimishes the TimeScale, you'll need to modify the Gravity settings as well for the rigidbody. TimeScale / 2 -> Gravity *2 for example. That might do the trick.
Hi I have already done it, but it seems that is not like TimeScale / 2 -> Gravity *2, gravity has to be more than twice the time, in my tests seems to be more like 4 times the original gravity. I will check it better. Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613170417im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
AddForce and Rigidbody 2D - Body doesn't move correct number of units per second? 0 Answers
Vertical push doesn't let the object fall down instantly 1 Answer
mass spawning rigid bodies but only some keep the given velocity 0 Answers
Limit Rigidbody Velocity 4 Answers