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 ZeusAllMighty11 · Oct 15, 2014 at 03:12 PM · rigidbodygravityverticesraycasts

Check if entire box collider has air below, instead of just a point on the box?

I'm currently working on a Super Mario Bros remake, and it's going well aside from a few collision issues.

I'm using Raycasts to determine the situations to apply gravity. In this specific issue, I am spawning a mushroom item, which is a cube with a texture, has a box collider, mesh renderer, a rigidbody, and the script to handle it all. I am using it as a trigger, so a player can pass through it which I think is smoother than grabbing it when they touch the edge of it.

Current mushroom item script: http://pastebin.com/jCjZiaYX

The way the gravity works, is:

  1. Mushroom has a rigid body, constrained on all axes except X (left/right or 'horizontal')

  2. If the Mushroom doesn't have an object within 0.6 of it's bottom, I assume it is floating and I should apply gravity to it.

  3. Unconstrain Y axis so rigidbody can work it's magic

The problem is, it doesn't check if 4 points are all in the air, it only checks for 1 point of the box, which I assume is the very center vertice. I'm wondering if there's a way to check if the entire bottom of the box (or the 4 bottom vertices), if they are all floating.

So the real issue is that it is triggering the OnTrigger method when the corner of the mushroom catches on the floor it is going to fall off of. This wouldn't be much of an issue, except I am also checking if the mushroom hits a wall so it can flip directions (If you ever played any mario game, you would know what I mean).

Thanks!

Edit: I'm open to completely rewriting this system too, so don't be afraid to make a better suggestion than what I have.

Comment
Add comment · Show 1
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 MrSoad · Oct 15, 2014 at 03:29 PM 0
Share

Any chance you could post your code here as a .zip file. $$anonymous$$y internet connection is not the best and the site you posted on is not responding well at all. I will have a look at your code and see if I can help you if you do. Thanks.

fafase's solution is a good one!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by fafase · Oct 15, 2014 at 03:36 PM

Your raycast is going from the center since you use transform.position. As a result, once half of the square has nothing under, it considers that it should fall. Instead of casting from center, cast from side, just add two empty objects at the side edges and cast down, then if both are false (and only if both at the same time), it means it should go down.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Make object use gravity without rigidbody. 2 Answers

Make A Cube 'Sticky' 4 Answers

Rigidbody AddForce/Velocity & gravity - mysterious interference 1 Answer

I have a planetary gravity script; how do I make the object speed up? 1 Answer

Tranform Animation Curve ruins Gravity 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