- Home /
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 ??
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 ?
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;
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().
Your answer
Follow this Question
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