- Home /
How to turn on the gravity of multiple objects with the same tag after collission?
So I know I cannot grab the transform of a game object but here is the Code I currently have. I want to to turn on gravity from the rigidbody for all of these objects with the same tag. Any Ideas? I am thinking I will have to use arrays but I may be wrong. Code is (JS)
var Camerashake : Camerashake;//script
var rumblesound : AudioSource;
var rumblesoundstop : AudioSource;
var stalagtite = GameObject.FindGameObjectsWithTag ("Fracture1");
function Start () {
}
function Update () {
}
function OnTriggerEnter (other : Collider) { //T
if (other.gameObject.CompareTag ("Player")){
print("Collision!");
stalagtite.rigidbody.useGravity = true;
Camerashake.enabled = true;
audio.Play();
yield WaitForSeconds(9) ;
audio.Stop();
}
}
Answer by highpockets · Aug 12, 2013 at 04:50 AM
Take a look at the answer I posted in this link:
It will work the same for you.
You will have to make the necessary adjustments for JS as it is in C#.
Answer by medman6107 · Aug 12, 2013 at 02:57 PM
Actually I should of been more precise, this is a group of children on an object, so I just created a specific script on the parent and used this code under function start:
Codes is JS:
for (var child : Transform in transform) { child.rigidbody.useGravity = true ;}
Then I can just turn on that script after hitting the collider and it will apply gravity to all objects.
Your answer
Follow this Question
Related Questions
How to find layer instead of tags 3 Answers
lookAt nearest object to another object 1 Answer
Find children by tag from Player 1 Answer
How to set velocity of Rigidbody without changing gravity? 1 Answer
tag distance script 2 Answers