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:

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 :slight_smile:

bullet.rigidbody.velocity = new Vector3 (1f, 1f, 0f) * speed * (Time.timeScale / 1f);

Exactly what @MrSoad suggested.

Here’s some informations to clarify your problem :

  1. 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).

  2. 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.

  3. 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.

  4. 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.