Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by smirlianos · May 02, 2013 at 06:50 PM · collisionrigidbodyinstantiateenterother

OnCollisionEnter is slow...

Hello!

I have this script attached to my bullet object that is supposed to destroy it when touching a Collider, and Instantiate a particle.

The problem is that the bullet goes so fast, that the particle Instantiate not exactly the same time when the bullet collides, but a bit later, after the bullet has changed its direction from the hit, because the OnCollisionEnter function doesn't destroy the bullet on time...

 #pragma strict
 var DirtHit : GameObject;
 
 function Start () {
 rigidbody.AddRelativeForce (Vector3.forward * 1000);
 yield WaitForSeconds(3);
 Destroy(gameObject);
 }
 
 function OnCollisionEnter (other : Collision) {
 Destroy(gameObject);
 Instantiate(DirtHit, transform.position, transform.rotation);
 }


It has a cube collider, if this helps...

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
3
Best Answer

Answer by alexanderbrevig · May 03, 2013 at 08:33 AM

Let's say your game runs at 60 frames per second. If we assume that the deltaTime between each frame stays stable (best case scenario) then the bullet travels 1/60 * 1000 = 16.666 units between each frame.

I would therefore use a Raycast each tick, forward more than 16.666 units. Try 20 and see what happens.

When you detect a RaycastHit, you could use the position of that hit for the DirtHit instant.

Comment
Add comment · Show 2 · 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 smirlianos · May 03, 2013 at 09:05 AM 0
Share

Thanks! But how I will insert the raycast on my script? It will be on the bullet or the gun?

avatar image Hamesh81 · May 03, 2013 at 09:57 AM 1
Share

Raycast from the bullet. If you search youtube for "Unity Bullet Holes" you should get a few good tutorials, even though you're not doing bullet holes the principle is very similar.

avatar image
0

Answer by SubatomicHero · May 03, 2013 at 08:22 AM

In the inspector have you tried altering the collision detected to either Continuous or Continuous Dynamic from Discrete?

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 smirlianos · May 03, 2013 at 09:02 AM 0
Share

Yes, it has the same result

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

15 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

Related Questions

OnCollisionEnter not triggering when two rigidbody collide via Instantiate 1 Answer

Detect Collision Again ( trigger OnCollisionEnter again ) 1 Answer

OnCollisionEnter not being called, between a Rigidbody and a Box Collider 1 Answer

Checking Collision on instantiated object 0 Answers

Instantiated object not colliding when not have a rigidbody?? 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