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 luniac · Jun 13, 2012 at 09:21 PM · collisionaddforceballfloor

Ball colliding with floor as it's rolling

I have a ball that has forces applied to it when i press the corresponding arrow keys. I didn't realize before that even if the ball is in the air, the arrow keys will still apply forces to the ball and it will be able to move in the air.

I'm thinking of fixing it by putting the movement code with the forces inside the OnCollisionStay check. That way the ball will only have forces applied to it when it's touching the floor(I assume I can put some kind of ignore tags on walls, etc later).

Is this a proper and efficient way of solving this problem, or is there a simpler more elegant solution, perhaps a unity function i'm not aware of?

Comment
Add comment · Show 6
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 luniac · Jun 13, 2012 at 09:38 PM 0
Share

To be more clear, what i mean is: OnCollisionStay ill set a toggle variable such as moveallow = 1; Then in the FixedUpdate() function ill have an if statement check the moveallow variable, and the movement addforce code will be inside.

And im just wondering if thats an efficient way of doing it, or is there some function im not aware of that's simpler and more elegant.

avatar image luniac · Jun 13, 2012 at 09:39 PM 0
Share

And OnCollisionExit i can set moveallow = 0 right???

avatar image luniac · Jun 13, 2012 at 09:41 PM 0
Share

OH OH maybe i can use OnCollisionEnter()to make moveallow = 1 and just use a floor tag to make sure it's touching the floor! Then OnCollisionExit() i can see if it's exiting the floor and then set moveallow = 0! This means the Collision check only happens 2 times and the entire time the object is on the floor, no collision calculations have to be done!!!

This sounds pretty elegant to me. Any opinions?

avatar image whydoidoit · Jun 13, 2012 at 10:05 PM 0
Share

Looks like you've thought that one through yourself :)

Sounds like it would work to me....

avatar image luniac · Jun 14, 2012 at 01:49 AM 0
Share

but how would YOU do it lol?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Ball Rotating Help 0 Answers

How can I apply a force to an object in the opposite direction of the object it's colliding with? 2 Answers

iPhone touch raycasting 1 Answer

i want to make an animation throw code 0 Answers

Ball jump on collision problem 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