- Home /
Collision between a flare and a object doesn't occur...
Hey There!
So I've this problem where I'm trying to make a "space torpedo" hit the target, however when both colliders interact, the script that destroys the torpedo doesn't work, and the torpedo stays there indefinitely...
The Ship has a group of 6 colliders, and the torpedo is an empty game object with a sphere Collider and a lens flare inside it. In order to the lens flare glow through the collider, I placed the primary game object in a TransparentFX layer.
And then I've this script that checks if it doesn't collide with the object that fired it, and if it hits a target, destroys itself:
function OnCollisionEnter (hit : Collision) {
if (hit.transform != launched.transform)
{
Destroy(gameObject);
Instantiate(explosion.transform.gameObject, transform.position, transform.rotation);
}
}
So, anyone can tell me what's been done wrong here?
Thanks in advance.
JPB18
EDIT: Here's the script responsible for the torpedo movement (also changed the collision script):
function FixedUpdate () {
if ( isCalc != true)
{
//calc the flight time
var time = travel_time(target.position, launched.position, speed);
isCalc = true;
}
//fly!!!!
StartCoroutine(flight(transform, launched.position, target.position, time));
}
//calculates the distance between the origin and the target
function travel_time(target : Vector3, start : Vector3, speed : float) {
var distance = Vector3.Distance(start, target);
return distance/speed;
}
//flight Coroutine
function flight (ThisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float)
{
var i : float = 0;
var rate : float = 1/time * Time.deltaTime;
while (i < 1)
{
i += rate;
ThisTransform.position = Vector3.Lerp(startPos, endPos,i);
yield;
}
}
Thanks, it now hits the target... However, the lens flare now doesn't show up... (I added the rigidbody to the main game object).
Well what is it attached to? If it's the torpedo then you just destroyed it! You need to make sure that the thing with the lens flare stays alive for long enough to see it.
The point is that the flare doesn't show up, even before it hits the target... And I can put any distance I want between the ship that's launching it, and the target, and it doesn't show up... In fact, it gets destroyed imediatly, even though it records the target as being hit... (using a Debug.Log)
Oh make your rigidbody is$$anonymous$$inematic = true - its possible gravity is messing with things... Otherwise, hard to tell without seeing more code.
It's true, and the gravity is set as zero (since it's space), as well the rigidbody's use gravity = false... Also what happens (after adding a test explosion), is that the target is hit immediatly...
Answer by whydoidoit · Nov 18, 2012 at 03:40 PM
I would imagine it's a need for Rigidbodies - see this article
Your answer
Follow this Question
Related Questions
What drawback of frequently changing of Game Object's Layer? 0 Answers
Ghost collisions problem: RigidBody player bounces, when moving on platform edges 2 Answers
Only Take Damage Once with Multiple Colliders on Player 1 Answer
get only one colliding body 3 Answers
Ignore collisions between a certain collider and a layer 2 Answers