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 UnbreakableOne · Sep 29, 2014 at 04:16 PM · rigidbodyrigidbody2dbullet

Problem with fast bullets (tunnelling effect)

Hi,

I'm facing the tunneling effect problem, which is fast bullets skip certain small objects that appear on their path.

I'm using 2D and my bullets have rigidbody2D and I enabled "Continuous" on Collision Detection via Inspector.

Here is how I fire a single bullet:

 Rigidbody2D bulletInstance = Instantiate(BulletPrefab, transform.position, Quaternion.Euler(new Vector3(0,0,0))) as Rigidbody2D;
             bulletInstance.velocity = new Vector2(BulletSpeed, 0);

What am I missing? Is my problem is that I change velocity of the Rigidbody2D?

Thanks.

Comment
Add comment · Show 5
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 robertbu · Sep 29, 2014 at 05:02 PM 2
Share

Try decreasing the FixedTimestep: Edit > Project Settings > Time. This does increase the load the physics engine places on the app. You may also want to rewrite the DontGoThroughThings script in the Wiki for 2D.

avatar image Habitablaba · Sep 29, 2014 at 05:42 PM 0
Share

@robertbu, you should really make that an answer ins$$anonymous$$d of a comment. What you need (and what the DontGoThroughThings script provides) is ray casting. If you don't understand why, or want more information, that can totally be provided.

avatar image UnbreakableOne · Sep 29, 2014 at 07:02 PM 0
Share

Thanks. I'm interested to know why "Continuous" doesn't solve this. Are my bullets moving way too fast for even Continuous feature to work and provide proper CCD?

avatar image UnbreakableOne · Sep 29, 2014 at 07:15 PM 0
Share

I decreased value of fixed time step to 0.01 and apparently it fixed the problem.

Would someone please tell me pros and cons of using raycasts vs. decreased time step on a 2d game? I.e. which one is more expensive in which ways.

Thanks

avatar image fafase · Sep 30, 2014 at 03:47 AM 0
Share

Raycast is only valid for tiny objects with basic shape, like a bullet. With a more complex shape, you'd have to place multiple raycasts which in the end would turn out heavy. Continuous detection is then better.

1 Reply

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

Answer by UnbreakableOne · Oct 02, 2014 at 09:23 AM

What I ended up with and seems to work best is to change DontGoThroughThings for 2D, spend a day pulling my hair out with layer masks, and apparently everything works.

What I love about it is that I can increase speed of my bullets to any aribtrary value and they always hit the target.

Thanks

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.

Follow this Question

Answers Answers and Comments

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

Related Questions

Help with translation and rotation on a rigid body 2D 0 Answers

My bullet wont move forward 1 Answer

Rigidbody2D adding force vs modifying velocity for character jump 1 Answer

2D rigidbody makes my character slowly rise 1 Answer

"Freeze Position" applied to an axis affects the bounciness of the object's collider on that axis. 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