Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 DGArtistsInc · Mar 06, 2012 at 03:34 AM · rigidbodycolliders

Rigidbody Collider Issues

Ok i have a rocket launcher that shoots out a rocket... Thats not the problem it shoots fine. The rocket is suppose to collide with any objects in its path and explode... I have an imported terrain(because flash doesn't allow you to use the unity's terrain) that has a mesh collider. The rocket shot has a capsule collider. The rocket however collides with every other object except the Terrain... It collides occasionally but not very often and i want it to collide every time. Rocket Script:

 using UnityEngine;
 using System.Collections;

 [RequireComponent (typeof (Rigidbody))]

 public class RocketExplode : MonoBehaviour {

 public int timeOut;
 public GameObject explosion;
 public GameObject character;
     private Vector3 position;

 void Start () {
     timeOut = 3;
     character = GameObject.FindWithTag("Player");
     Invoke("Kill", timeOut);
     Physics.IgnoreCollision(character.collider, collider);
 }

     void FixedUpdate()
 {
     if(transform.position != position)
     {
         if (Physics.Linecast (transform.position, position)) 
         {
             Instantiate(explosion,transform.position,transform.rotation);
             Kill();
         }
         position = transform.position;
     }
 }
 
 void OnCollisionEnter(Collision collision)
 {
     ContactPoint contact = collision.contacts[0];
     Quaternion rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
     
     Instantiate (explosion, contact.point, rotation);
     Kill();
 }
 
 void Kill()
 {
     ParticleEmitter emitter = GetComponentInChildren<ParticleEmitter>();
     if(emitter)
         emitter.emit = false;
         
     transform.DetachChildren();
     
     Destroy(gameObject);
 }
 }

Also on top of that the rocket doesn't destroy itself after it explodes... Any help is appreciated. Added in what syclamoth told me to do... did i do it wrong or something?

Comment
Add comment · Show 11
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 DGArtistsInc · Mar 07, 2012 at 02:18 AM 0
Share

I have heard that setting the mesh collider to convex will work but the terrain is rather curvy(if ya know what i mean) and setting it to convex would make the collider boxy(not what i want.)

avatar image syclamoth · Mar 07, 2012 at 03:08 AM 0
Share

Try augmenting the rocket's collision detection with a simple raycast collider to catch anything that the capsule misses.

avatar image DGArtistsInc · Mar 07, 2012 at 03:31 AM 0
Share

Are suggesting a Physics.OverlapSphere or something else?

avatar image syclamoth · Mar 07, 2012 at 03:40 AM 0
Share

No, I mean simply using Physics.Linecast between the previous position and the current position every FixedUpdate step. If it detects a collision, calculate reflection/damage/destruction as you see fit. It's not as accurate as rigidbody collision, but it's faster and more reliable, and for small objects or fast objects it doesn't make that big a difference anyway.

avatar image hijinxbassist · Mar 11, 2012 at 12:58 AM 1
Share

var position:Vector3;
function Start()
{
    position=transform.position;
}
function Update()
{
    if(position!=transform.position)Debug.Log("Position has changed");
    //make sure to cast before resetting position to transform.position
    position=transform.position;
}
Show more comments

1 Reply

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

Answer by syclamoth · Mar 12, 2012 at 12:45 AM

Augment the discrete rigidbody physics engine with a simple linecast collider:

 var lastPos : Vector3;
 var hitLayers : LayerMask;

 function Start()
 {
     lastPos = transform.position;
 }

 function FixedUpdate()
 {
     if(Physics.Raycast(lastPos, position, hitLayers))
     // Make sure you use a layermask that excludes the bullet itself!
     {
         // POW!
     }
     lastPos = position;
 }
Comment
Add comment · Show 1 · 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
avatar image DGArtistsInc · Mar 13, 2012 at 12:28 AM 0
Share

Thanks dude your a savior this actually works! Thanks!

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity3D Rigidbodies acts like objects is elastic and falling inside eachother 0 Answers

Having problems with playing a sound (C#) 2 Answers

OnMouseDown not firing if character isn't touching ground 0 Answers

Collider Doesn't Rotate in Sync With Mesh 1 Answer

Colliding without gravity 2 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