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 cmo · Jul 14, 2013 at 10:33 AM · collisionontriggerenteroncollisionentercollisiondetection

Response speed in OnCollisionEnter / OnTriggerEnter

I'm attempting to set up a simple 2D prototype that uses OnCollisionEnter (I've also tested OnTriggerEnter) to stop a moving object at precise intervals, but having some problems that seem like they may be related to when / how those functions are called.

Here's what I have / need:

  • 10 platforms spaced out at exact intervals

  • A "falling" object (which I'm actually moving with a Lerp in Update; the object itself is kinematic / not affected by gravity)

  • As the object falls, it should hit each platform and stop on it until set to be falling again

The platforms trigger / call OnCollisionEnter properly each time the falling object hits them. However, each time I run the prototype, some of the platforms malfunction, letting the object fall partway through before changing the variable that stops it.

Some previous answers I've seen suggest that OnTriggerEnter uses physics and thus may call too infrequently for use with an object that's moving quickly, but it's suggested that OnCollisionEnter should be "faster". I'm seeing the same problem with both, though. Is there some way I can get either to work, or some obvious problem with using them in this way?

For reference, here's the simple code I'm trying to use.

This is on the falling object:

     void Update () {
         if (falling) {    
             originalPos = this.transform.position;
             targetPos = this.transform.position + new Vector3 (0f, -0.2f, 0f);
             
             this.transform.position = Vector3.Lerp (targetPos, originalPos, fallRate);
 
             if (fallRate > -1f) {
                 fallRate = fallRate - 0.01f;
             }    
         }
     }

And this is on each platform:

     void OnCollisionEnter (Collision piece) {
         PieceScript stopIt = piece.gameObject.GetComponent<PieceScript>();
         stopIt.falling = false;
         Debug.Log ("platform triggered:" + piece.gameObject.name);        
     }
Comment
Add comment · Show 4
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 cmo · Jul 14, 2013 at 07:16 PM 0
Share

Yep.. that's correct Bunny. I got so focused on the rate of collision / trigger that I forgot to think about how I was moving the object. Thank you!

avatar image Bunnybomb7670 · Jul 14, 2013 at 07:22 PM 0
Share

np :) so does it work now?

avatar image cmo · Jul 14, 2013 at 07:24 PM 0
Share

If I set the transform lerp to a lower speed, the pieces align perfectly on the platforms, so... yes, more or less. I'll just have to fiddle with how they move, I guess.

avatar image Bunnybomb7670 · Jul 14, 2013 at 07:46 PM 0
Share

sweet, good job, im gonna upgrade my post to an answer :)

1 Reply

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

Answer by Bunnybomb7670 · Jul 14, 2013 at 11:34 AM

Exactly how fast is the object moving at? if it is moving too fast, it wont pick it up because technically, when an object moves, it is teleporting every frame, the faster you get, the bigger the jump between frames, if it is going so fast, it may teleport straight past the object therefore not triggering it.

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

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

simple onCollision and onTrigger problem 1 Answer

OnTriggerEnter() and OnCollisionEnter(), OnControllerColliderHit() not working with character controller 2 Answers

OnTriggerEnter do not triggers 1 Answer

On Trigger Enter, Collide with object, specific collision 1 Answer

Colliding two GameObjects 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