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 Neeko · Jan 07, 2014 at 06:48 PM · collision detectionwindowsframeratefixedupdateandoid

Raycasting based collision detection fails on slow framerates

I'm experiencing an odd issue with my collision detection. I'm using the Update method to read input, and I have the collision detection code running in the FixedUpdate method (per the usual suggestion so that the code is always executed at a fixed rate, regardless of framerate). The fixed timestep is set at the default 0.02.

However, when the framerate is low (below 30), the collision detection doesn't always work. The player can easily fall through the collision layer, though sometimes they don't.

It's my understanding that FPS shouldn't have an effect since I'm calling the collision detection logic in FixedUpdate.

If you'd like to see the actual collision detection code, here's a Gist to an abbreviated version.

Edit: Based on Gruffy's comment, I rearranged some of the code so that all of the input polling occurs in Update and I perform the actual raycasting and final translation in LateUpdate, which alleviates the problem, but doesn't completely remove it.

Comment
Add comment · Show 7
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 Gruffy · Jan 07, 2014 at 07:34 PM 0
Share

If you were updating your position in Update, then any collision detection in Fixed Update would be too late for the moment of collision as Update is called before Fixed Update regardless, so anything in fixed update that relied on a translation in Update could never receive, churn and output the data in time.

consider this... Fixed update loops every actual second Update loops at 60 frames per sec with the above in $$anonymous$$d, your dilemma is pretty clear, as my previous waffle up-top digresses upon

Who told you Collisions go into FixedUpdate anyway. Physics is happy in there but Unity offers theri own functions to carry out collision outside of any FixedUpdate method call.

Collision is found through one of two Unity methods(to start with), void/function OnCollisionEnter(Collision col/ col: Collision) or void/function OnTriggerEnter(Collider col/ col: Collider) (C#/UnityScript)

Humbly, I think its best you read this before you go any further bud.

Collision Unity Scripting Reference

Hope it help-s for now.... Why dont you post your code, it may be easier to example (A) what im saying & (B) what it is exactly in the code that is causing you your problem Take care dude:0 Gruffy

avatar image Neeko · Jan 07, 2014 at 10:49 PM 0
Share

I've managed to cap the framerate on a Windows build through the use of Application.targetFrameRate, and when I set the framerate to 20, I'm experiencing the same issue I see on Android, so the problem is related to a slow framerate, which I feared.

But you may be right about when I'm applying the translation. First, I tried updating my position in FixedUpdate as well (see the code sample). I've even moved the input polling inside FixedUpdate, just to see if that had any effect. That didn't help. I'm now doing all of the input polling inside Update and using LateUpdate to perform the actual raycasting and perform the final translation, which seems to alleviate the problem greatly, but occasionally I'll notice the player go through the collision layer when he shouldn't.

Since I'm doing a 2D platformer, I'm using raycasting to detect collision layers and adjust entity movement as appropriate, so I can't use the Unity OnCollision methods.

I've included a link to the code in the original question, but here it is again, https://gist.github.com/$$anonymous$$adballNeek/9162e6f05b88e49b0a33.

avatar image ShaneTheVeryTall · Jan 27, 2014 at 11:34 PM 0
Share

Any progress with this? I've also been working on a platformer system that uses raycasting to detect when it hits the ground, etc. Sometimes (very rarely) when I have a sudden drop in frame rate, my character will go right through the ground.

Any help would be appreciated.

avatar image Gruffy · Jan 28, 2014 at 11:19 AM 0
Share

Okay, I will take a further look at it. Gimme the day to come back to you , as I is WELL busy today

avatar image Neeko · Jan 28, 2014 at 07:40 PM 0
Share

@ShaneTheVeryTall The code in the gist I linked has been working fine for me now, I haven't noticed the issue anymore. You may want to open up a new question with your code for further help.

@Gruffy I'm not sure what you're referring to. As already commented, the gist I linked most certainly isn't a single script file (it's abbreviated code for three separate classes that I've pasted into a single gist, for the sake of brevity), nor is it slow. The framerate drop I was witnessing was due to a completely separate issue, which I've since resolved. Thanks again for the help though.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Xtro · Jan 28, 2014 at 07:59 PM

Do the raycasting and the input reading both in the FixedUpdate.

Why do you even read the input in the Update if you are gonna move it in FixedUpdate?

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 Xtro · Jan 30, 2014 at 09:01 PM 0
Share

Can you please mark the correct answer if you fixed that problem?

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

21 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

Related Questions

Getting Input every few frames? 2 Answers

trying to regulate character speed. 1 Answer

"Build" for Android Platform asks for save location but nothing happens 0 Answers

Physics behaviour changing with framerate - Is FixedUpdate() actually working properly? 3 Answers

Unity Physics frame rate. void FixedUpdate 3 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