- Home /
Collider detection problems!
What I want
I have a lazer gun. If the lazer gun hits a block a script will activate its gravity. I have manny blocks. Any every block must fly only if the lazer touch that block not a other block.
The Problem
All the blocks have the same tag for testing I have only 1 script activated. But now if the lazer touches 1 block with the same tag the other block will fly. I want the the lazer must touch that block to fly now its not so.
does anyone know how to do this.
The script
var Lazer : GameObject;
var Colliding : boolean;
var RBody : RigidBody;
function Update () {
if(colliding)
{
RBody.useGravity = true;
RBody.isKinematic = false; //this script is rewritten ignore errors in the script qua grammar
}
}
function OnTriggerEnter (col : Collider)
{
if(col.collider.tag == Lazer.tag)
{
Colliding = true;
}
}
Can you post the script where you handle the collision? It would be easier to see what's wrong.
@$$anonymous$$angas I have edited the question. Now the script is there
Answer by HarshadK · Jan 13, 2015 at 10:12 AM
Add the script below to each of your blocks.
var Lazer : GameObject;
function OnTriggerEnter (col : Collider)
{
if(col.collider.tag == Lazer.tag)
{
// Once the laser hits we set everything once to make the block fly
rigidbody.useGravity = true;
rigidbody.isKinematic = false;
rigidbody.WakeUp(); // This is used to wake up the rigidbody
}
}
Now you do not need to have any other script on your Lazer game object to handle the flying thing. So if there is any script on Lazer for selecting the block to fly just remove it.
Your answer
Follow this Question
Related Questions
Issue with my Teleport Script 1 Answer
Animation Script not working. 1 Answer
Script doesn't find other script 0 Answers