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 Dede24 · Nov 12, 2012 at 03:19 PM · collisionphysicsprojectiles

Projectiles too fast for Physics

hey guys,

I'm having a problem with projectile physics.

The projectiles in my game are very fast, so fast in fact, that OnTriggerEnter events, are recognized too late sometimes, and the bullet is technically able to fly through a thin wall.

Heres an example code:

 void OnTriggerEnter(Collider other)
 {
     if (COLLIDER == WALL)
     {
         DESPAWN PROJECTILE
     } 
 }

is there any way to speed up the collision detection with OnTriggerEnter. So that the collision calls are framerate independent?

The projectile is moved like this btw. (2D game):

 transform.Translate(Vector3.up * Time.deltaTime * speed);

I thank you very much.

Comment
Add comment · Show 1
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 AlucardJay · Nov 12, 2012 at 03:24 PM 0
Share

http://wiki.unity3d.com/index.php?title=DontGoThroughThings

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Graham-Dunnett · Nov 12, 2012 at 03:23 PM

Perform a ray cast from the position the projectile is now, to where it'll be in the next frame. If the ray hits anything, then so will the projectile. You can use the distance along this ray where the collision occurs to tell you when the bullet would hit.

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

Answer by Owen-Reynolds · Nov 12, 2012 at 03:56 PM

Can look at / read the CollisionDetection options in the rigidbody, to force it to check "in between" frames.

But, if it's going that fast, it may not look good anyway, and the raycast method may be better.

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

Answer by Dede24 · Nov 12, 2012 at 05:07 PM

I found a more simple approach, which seems to get the job done. I basically just made the OnTriggerEnter event a coroutine, which works with Fixed Update:

 IEnumerator OnTriggerEnter(Collider other)
     {
         yield return new WaitForFixedUpdate();
         if (WALL)
         {
             DESPAWN
         } 
     }

on top of that, I reduced the Fixed Timestep in the Timemanager to 0.005. Now no bullet flies through a thin object anymore.

But I might go back to the raycast method, if this approach doesnt work over the long run.

But thanks to all of you, for the suggestions.

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 Owen-Reynolds · Nov 12, 2012 at 09:10 PM 0
Share

Doubt the coroutine does anything extra -- gotta be just the change in fixedTimeStep.

The physics system is already checking OnTrigger during each fixedUpdate.

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

12 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

Related Questions

Drag & Drop GameObject with MovePosition shoots other Gameobject away in case of them colliding 1 Answer

Make Ray hit own collider 1 Answer

How to make physics collision dotted simulation like bubble shooter ? 2 Answers

Disable inertia tensor calculations on rigidbody? 0 Answers

Collision Query 1 Answer


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