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 Sausagesauce · Nov 16, 2013 at 12:42 AM · rollingdicedetecting

Dice Rolling Detection

How would I create a system that rolls a dice, and detects what the side lands on? I COULD just use Raycasts or Vector3.Dot or something, but how would I do that with a four-sided dice? Eight-sided? Ten-sided? Twenty-sided? Is there a simple system for doing this? Is it possible to simply detect the side that is touching the floor?

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 Huacanacha · Nov 16, 2013 at 01:49 AM 0
Share

If you need complete flexibility with die sizes, shapes, and number of faces, just check all faces for the normal closest in angle to Vector3.up once the die comes to rest. Using the Dot product this is very little calculation compared to, for example, having colliders on each face (likely more costly per set of calculations plus run each physics update).

 Vector3.Dot(Vector3.up, side.normal); // Find the result closest to 1!

You need some meta-data for your sides in any case to define what number or result they represent, so just store the normal as well. It's probably best to pre-calculate the local space normal in Start() then transform Vector3.up to local space before calculating the dot products.

I'm not sure if this answers you fully so I'll leave it as a comment... are you also thinking how to deter$$anonymous$$e which faces are what value on the die etc?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tWayfarer · Nov 16, 2013 at 03:03 AM

You can get the collision's contact points, and from there find the direction to from the centre to the collision point. You'll have to figure out in advance the direction to each face, which there's probably an elegant way of doing which I am unaware of. Rigidbody physics could probably handle rolling the die itself, after an initial force applied. Then, just wait until it's stopped, use the contact points to find the face on the bottom, compare the angle and you've got the face. If you want the opposite face to the one on the bottom, just reverse the angle before comparing 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

19 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

Related Questions

How can you grab an object on the screen and shake it? 0 Answers

Dice Animation and Face Determination 7 Answers

What is package or asset can control result the dice. 0 Answers

Need help, Katamari Game (Plz Help) 1 Answer

How do I make my character curl up? 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