• 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 JPB18 · Nov 18, 2012 at 03:34 PM · collisioncolliderslayersflare

Collision between a flare and a object doesn't occur...

Hey There!

So I've t$$anonymous$$s problem where I'm trying to make a "space torpedo" $$anonymous$$t the target, however when both colliders interact, the script that destroys the torpedo doesn't work, and the torpedo stays there indefinitely...

The S$$anonymous$$p 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 t$$anonymous$$s script that checks if it doesn't collide with the object that fired it, and if it $$anonymous$$ts a target, destroys itself:

 function OnCollisionEnter ($$anonymous$$t : Collision) {
     
     if ($$anonymous$$t.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 (T$$anonymous$$sTransform : Transform, startPos : Vector3, endPos : Vector3, time : float)
 {
     var i : float = 0;
     var rate : float = 1/time * Time.deltaTime;
     
     w$$anonymous$$le (i < 1)
     {
         i += rate;
         T$$anonymous$$sTransform.position = Vector3.Lerp(startPos, endPos,i);
         yield;
     }
 
 
 }
Comment
Add comment · Show 7
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 JPB18 · Nov 18, 2012 at 03:47 PM 0
Share

Thanks, it now hits the target... However, the lens flare now doesn't show up... (I added the rigidbody to the main game object).

avatar image whydoidoit · Nov 18, 2012 at 03:49 PM 0
Share

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.

avatar image JPB18 · Nov 18, 2012 at 03:58 PM 0
Share

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)

avatar image whydoidoit · Nov 18, 2012 at 04:00 PM 0
Share

Oh make your rigidbody isKinematic = true - its possible gravity is messing with things... Otherwise, hard to tell without seeing more code.

avatar image JPB18 · Nov 18, 2012 at 04:15 PM 0
Share

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...

Show more comments

1 Reply

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

Answer by whydoidoit · Nov 18, 2012 at 03:40 PM

I would imagine it's a need for Rigidbodies - see t$$anonymous$$s article

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

What drawback of frequently changing of Game Object's Layer? 0 Answers

Why does my player fly through my barrier? 2 Answers

Colliding fast moving object with a slow moving object 1 Answer

How to make two objects not go through each other (without physics) 3 Answers

Reacting to terrain height changes without a rigidbody component 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