Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ParkourTeddy · Aug 05, 2018 at 08:43 PM · triggerrigidbody2drigidbody.velocity

Is there any way to increase a triggers check rate?

I tried using a trigger to see when a ball entered an area. Everything worked as long as the ball moved at a low speed. Although when the ball was moving at a high speed the trigger would not detect the ball even though the ball had passed through the trigger. Is there any way to increase the check rate of the trigger or prevent triggers from missing objects moving through at high speeds?

I'm currently using rigidbod2D.velocity to move the ball.

I threw together a quick project to showcase the problem. alt text The blocks on the sides are triggers that inverse and increase the balls x velocity. The ball script...

 public class Ball : MonoBehaviour {
 
     Rigidbody2D rb2d;
     // Use this for initialization
     void Start () {
         rb2d = GetComponent<Rigidbody2D>();
 
         rb2d.velocity = new Vector2(6, 0);
     }
 }

The block script...

 public class Block : MonoBehaviour {
 
     private void OnTriggerEnter2D(Collider2D collision)
     {
         GameObject obj = collision.gameObject;
         if(obj.CompareTag("Ball"))
         {
             Rigidbody2D rb = collision.GetComponent<Rigidbody2D>();
             rb.velocity = new Vector2(-rb.velocity.x * 1.1f, rb.velocity.y);
         }
     }
 }


How can I prevent the ball from flying threw the trigger?

2018-08-06-19-38-59.gif (55.5 kB)
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
1

Answer by IvovdMarel · Aug 06, 2018 at 02:04 AM

Trigger checking is NOT related to FPS, as it runs in the FixedUpdate, as opposed to the Update.

https://docs.unity3d.com/560/Documentation/Manual/ExecutionOrder.html

FixedUpdate (and Physics) by default runs every 0.02 second. In Edit > Project Settings > Time you can adjust your Fixed Timestep.

Alternatively, try changing the interpolation/extrapolation options in the Rigidbody (see docs for more details)

Comment
Add comment · Show 3 · 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 ParkourTeddy · Aug 06, 2018 at 05:59 PM 0
Share

Lowering the timestep definitely uppers the triggers checkrate. Interpolation and extrapolation does not seem to have any effect on the ball when it comes to preventing the ball from flying past the blocks in my example. By changing the timestep I was able to keep the ball from flying through the triggers for longer but when the ball reached a higher speed it still flew past the triggers like in the example.

Is there any good way of completely preventing the ball from passing the triggers unnoticed?

avatar image Bunny83 ParkourTeddy · Aug 06, 2018 at 06:14 PM 0
Share

Yes there is. Just tell your object: DontGoThroughThings ^^.

This script is already 11 years old. Discrete time step simulation would always have the problem at a large enough speed it would penetrate through any colliders. This is actually similar to the Wagon-wheel effect.


The solution in the script is to actually perform a raycast along the distance the object would travel between two time steps.

avatar image ParkourTeddy Bunny83 · Aug 06, 2018 at 06:37 PM 0
Share

Thanks that's cool. But I noticed that if I switch from using triggers to colliders and set the rigidbodies collision detection to continuous that the ball will never pass the collider (and I think always trigger the onCollisionEnter) no matter the speed, is there no such option for triggers?

avatar image
-1

Answer by SamohtVII · Aug 06, 2018 at 01:55 AM

The issue would be the FPS would it not. As the ball moves at each frame it moves bit by bit. At, for example, 30 fps over 30m distance it does 1m/frame. At 60m it goes 2m/frame and so on. If it hits (For example) 4m at frame 4 and 6m at frame 5 and the collider is at the 5m mark it will not detect it. I know this isn't an answer but maybe with that knowledge a solution can be found. Possibly checking the x and y each frame and comparing that with the collider x and y and seeing if it would have passed through.

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

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

Related Questions

Set Object Rotation based on Collision (2D) 0 Answers

How do I make it so the player cant spam the dash 1 Answer

BoxCollider2D, Trigger not working 1 Answer

Gameobject going past target when using rigidbody2d.addforce 1 Answer

How do I add forward velocity to a Rigidbody2D? 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