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
0
Question by abssuper20 · Jan 17, 2018 at 02:04 AM · unity 5physicscolliderstriggers

Use Of OnCollisionStay()?

So i have been studying triggers and colliders recently and how they are used but i don't seem to understand the use of OnCollisionStay? I understood how and why OnTriggerStay is needed but couldn't understand why OnCollisionStay is needed or even used. Can someone explain it with an example?

Comment
Add comment · Show 2
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 abssuper20 · Jan 17, 2018 at 01:29 PM 0
Share

Thank you both. I got it clearly now

avatar image meat5000 ♦ · Jan 17, 2018 at 01:53 PM 0
Share

OnCollisionStay should really be avoided unless incredibly necessary. The per-frame processing will add massive load to the cpu. Intensive!

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by alelavoie · Jan 17, 2018 at 03:43 AM

It is called as long as the two bodies are colliding.

OnCollisionEnter -> OnCollisionStay - OnCollisionStay - ... --> OnCollisionExit.

For example, imagine you are working on a helicopter game and you want the helicopter's engine to run at 80% of it's maximum strength when the skids are touching the ground.

 void OnCollisionStay(Collision collisionInfo) {
     if (collisionInfo.gameObject.name == "Ground") {
         //Reduce motor strength to 80%
     }
 }

 

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
1

Answer by sparkzbarca · Jan 17, 2018 at 03:43 AM

OnCollisionStay is used to do something while a collider is well colliding.

it's used for two objects continue to touch for a period basically.

ontriggerstay (which is basically to check an area) and on collision stay (which is used when two objects continue to touch) could be used in these two ways.

if you imagine a room with for example a fire pit, when your player walks in the fire pit you take damage, as long as you continue to stay in the flames, you keep taking damage.

for collision, if a wall was electrified, you continue to take damage while touching.

if you have something like a puzzle game where you push blocks around, on collision enter could be you do the animation to get in position to push, but on collision stay could be you push the block.

this would be useful for some kind of tomb raider/zelda puzzle where you need to push blocks around to jump on them to access areas or to place them on floor triggers to hold them down.

in gneral it's useful if you want something to happen but ONLY while two objects are directly touching.

Be that applying damage for touchign something, or pushing/pulling or even something like (i'm not saying htis is ideal)

on collision stay

if collider == terrain isgrounded = true;

you could use the fact that your touching the ground to keep updated on the fact that your grounded.

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

201 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 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

New physics creating a problem in working game. 0 Answers

Performance issues with trigger colliders and lots of projectiles. 2 Answers

OnTriggerEnter2D triggering multiple times when moving around inside the trigger area. 1 Answer

Curious about "Vortex" force (HELP) 2 Answers

Pulling boxes 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