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 Borzi · May 25, 2013 at 11:30 AM · collisioninstantiatecolliderparticlesfunction

Projectile Collision help

Hey, I am playing around with a projectile here and this function wont work (the particle wont instantiate). Thank you in advance:

 //Variables (START)_________
 //The particles that will Instantiate on hit
  
 var mudParticle : GameObject;
  
 //Variables (END)___________
 
 function OnCollisionEnter (hit : Collision)
 {
 if(hit.transform.tag == "floorMud")
     {
     Instantiate(mudParticle, transform.position, transform.rotation);
     transform.renderer.enabled = false;
     gameObject.GetComponent(SphereCollider).enabled = false;
     }
 }
Comment
Add comment
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

2 Replies

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

Answer by Supershandy · May 30, 2013 at 09:19 AM

If it's a case of the bullet only being detected when it is travelling slow, but you want your bullet to move fast, you may want to do a raycast from the bullet with a distance of one. I had a similar problem on my first ever demo game and my bullets just passed through objects.

A sample code would be

var bullet : Transform; var speed : float = 50.0//Or whatever you want it to be

Function Update ()

{ var hit = RaycastHit;

transform.Translate (0, 0, speed * Time.deltatime);

if (Physics.Raycast (transform.position, transform.forward, hit, 1) { if (hit.transform.tag == "Something")//replace with tag of object you want to destroy { Destroy (gameObject); } } }

This will mean that when the Raycast hits something with the tag of your object, it will react as soon as it hits and more accurately then the bog-standard colliders that Unity provides.

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 Borzi · May 30, 2013 at 01:23 PM 0
Share

Okay thanks! You were right, it only works when the bullet is travelling slowly. Because this is my first ever game, ill try both RayCast and colliders, so that I learn how both work. and decide on which I like best. This looks promising for getting collider systems to work!

avatar image
0

Answer by ricardo_arango · May 25, 2013 at 11:57 AM

Try debugging you code with MonoDevelop. You can add a breakpoint on line with the if (...) statement.

You can then check if the tag of the hit object is "floorMud" and verify that "mudParticle" isn't a null reference.

http://docs.unity3d.com/Documentation/Manual/HOWTO-MonoDevelop.html

Comment
Add comment · Show 9 · 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 Borzi · May 27, 2013 at 03:39 PM 0
Share

Okay, I did some debugging and a hit was not recognized/the function was not executed. I know that its a while since I last commented and I'm sorry, but it would be REALLY appreciated if you could help me with this...Thanks!

avatar image ricardo_arango ♦♦ · May 27, 2013 at 04:23 PM 0
Share

To get the collision events the script needs to be attached to the object that is colliding. You also need to make sure the collision layers are correct : http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html

avatar image Borzi · May 27, 2013 at 04:59 PM 0
Share

So with the object that is colliding, meaning the Bullet being fired I presume? Checked on the Layers and the collision $$anonymous$$atrix and it should be working...

avatar image ricardo_arango ♦♦ · May 27, 2013 at 08:22 PM 0
Share

Either one of them will receive the collision event if the script is attached to them.

avatar image Borzi · May 27, 2013 at 08:40 PM 0
Share

Hmmm...so clearly it SHOULD work but it doesn't. I doubt that this is a bug in Unity im guessing people must have used this type of system before. Guessing its similar to this: http://answers.unity3d.com/questions/48114/smoke-particle-on-point-of-collision.html

Show more comments

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

16 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Snap to Surface 1 Answer

How can I check if an instantiated object collides with another instantiated object? 1 Answer

How to read particle information from a OnParticleCollision call ? 0 Answers

Instantiate 1 object after 2 objects collide. ( C# ) 1 Answer

Making the collider change after being instantiate 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