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 0mr_ashutosh0 · Nov 06, 2014 at 04:20 PM · gameobjectsetactiveactivateinitializationdeactivate

ReActivate object with null movement ??

I have this interesting problem here. So there are 10 gameobject which are Initialised with the script and then i ACTIVATE them one by one and shoot them ( apply transform.up thats all ).

Now after the roll of that activated Gameobject is done ( i.e. to shoot the target ) i DEACTIVATE it and then ACTIVATE IT AGAIN

  • BUT THE PROBLEM IS ** after activating the gameobject again, the gameobject remembers his motion, and after reactivation behaves like he did before deactivation

SO HOW CAN I RE-ACTIVATE OBJECT WITH CONTROLLED MOVEMENTS ??alt text

problem.png (15.5 kB)
Comment
Add comment · Show 2
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 0mr_ashutosh0 · Nov 06, 2014 at 04:22 PM 0
Share

I am trying object pooling ins$$anonymous$$d of instantiate and destroy. i know that instantiate and destory will solve my problem. is there any way i can achieve this with pooling ?

avatar image 0mr_ashutosh0 · Nov 06, 2014 at 05:44 PM 0
Share

@robertbu and @Bunny83 Thank you guys :)

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Nov 06, 2014 at 04:28 PM

GameObjects don't move on their own. There has to be something that moves it. Either a script or like in your case probably a Rigidbody component. That Rigidbody has a velocity and an angularVelocity vector. There is no reason why they should turn themself back to 0,0,0 when you deactivate / reactivate the GameObject. So you have to set them to 0 manually:

 obj.rigidbody.velocity = Vector3.zero;
 obj.rigidbody.angularVelocity = Vector3.zero;
Comment
Add comment · 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
1

Answer by robertbu · Nov 06, 2014 at 04:27 PM

When using pooling you need to restore state. Assuming this is 3D, you want to do:

  obj.rigidbody.velocity = Vector3.zero;
  obj.rigidbody.angularVelocity = Vector3.zero;


...right before you activate the object. Depending on your game, it is sometimes easiest to have individual game objects restore their own state either when told to do so or using OnEnabled().

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

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

27 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

Related Questions

Activate Game object when in Camera view and deactivate when out of camera view. 2 Answers

Activating/Deactivating GameObject Problem :( 3 Answers

How to activate a gameobject via scripting ??? 3 Answers

Cannot deactivate / activate gameobject, even in editor! 6 Answers

How to activate/deactivate a component(Animator) when a specific game object was activated 0 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