Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 FritzPeace · Oct 26, 2015 at 05:00 PM · rigidbody2dactivaterigidbody.velocityactivationspeed issues

De-Activating object removes rigidbody velocity

Hello guys!

I got a background which instantiates prefabs, and adds a velocity to them. Since I got several "backgrounds", I deactivate them randomly sometimes. When activating them back, the prefabs that were previously placed do not keep their velocity. Is there anyway to make the rigidbody velocity remain after the re-activation?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by fffMalzbier · Oct 26, 2015 at 05:02 PM

As far as i know there is no build in direct onclick solution. Why not make a small script that stores the velocity on OnDisable() and writhes it back on OnEnable().

Comment
Add comment · Show 7 · 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 FritzPeace · Oct 26, 2015 at 11:03 PM 0
Share

I instantiate several images, such as mountains, clouds, trees, etc. I do not keep track of them, I just add velocity and set it to a value. If I disable them, and then re-enable them, the images that were already present have their velocity set at 0, while I'd like them to be the same as previously...

avatar image RLin · Oct 27, 2015 at 12:02 AM 0
Share

Do what @fff$$anonymous$$alzbier said. It will work.

avatar image FritzPeace · Oct 27, 2015 at 11:29 AM 0
Share

So every single prefab will have such script attached to it? Because I do not see a way to do such thing in the Spawner. The game is mobile, and I am afraid this will have performance issues. At least must be way better than having 5 backgrounds simultaneously working, 4 of them hidden and 1 apparent. So just so I am sure, I just add a script to the object saying: "OnEnable - rigidbody.velocity = velocity" "OnDisable - rigidbody.velocity=0"

avatar image Bonfire-Boy FritzPeace · Oct 28, 2015 at 02:50 PM 0
Share

You could add the component to each object in code if you prefer to do it that way.

And no, as fff said you'd need to store the velocity in OnDisable, and then use that stored value to set the velocity back in OnEnable. Both your bits of pseudocode are setting the velocity.

avatar image FritzPeace · Oct 28, 2015 at 01:34 PM 0
Share

@RLin @fff$$anonymous$$alzbier Do you know any other solution?

avatar image fffMalzbier · Oct 28, 2015 at 03:27 PM 0
Share

The script would not need to run update cycles so there is not performance problem. Storing the velocity in one vector3 should not be a memory problem. Sure you can combine it to one script that manages that all but it's probably unnecessary complexer than the one little script per object.

Show more comments

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

6 People are following this question.

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

Related Questions

Player moves differently in different aspect ratios 0 Answers

Unity License Activation 2 Answers

How to activate an object when another object deactivates? 1 Answer

Rigidbody2D.velocity is not working. 0 Answers

How would I detect my players velocity when it collides with something? 3 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