Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tzamora · Oct 31, 2014 at 11:54 AM · rigidbodyvelocity

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MrSoad · Oct 31, 2014 at 11:58 AM 0
Share

Can you not increase its velocity by the inverse of the time scale reduction?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tzamora · Oct 31, 2014 at 02:24 PM 0
Share

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.

avatar image
0

Answer by Mathieu_Dossmann · Oct 31, 2014 at 01:40 PM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tzamora · Oct 31, 2014 at 02:28 PM 0
Share

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

avatar image Mathieu_Dossmann · Oct 31, 2014 at 03:39 PM 1
Share

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.

avatar image tzamora · Oct 31, 2014 at 06:09 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges