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 /
  • Help Room /
avatar image
0
Question by Sysdia · Apr 18, 2016 at 03:29 PM · unity 5physicscollision detection

How to determine on collision if an object is rotated in a certain way

I have 2 objects and when they collide I want to execute some logic only when one of the objects is in a certain rotation.

If you look at the below image.

The white board on the left will have the small white block (with the black edge) collide with it, but i only want the logic to execute if the black edge is completely touching the white board.

So effectively if the z axis is rotated at 90' (and the y axis isn't rotated so it's facing away)

Here are some examples of how I would like it to work:

This should execute the logic because the black face on the object is rotated towards the white board (it can be rotated any way around the x axis and it would still be facing the board)

alt text

This one should not execute the logic on collision because the black face isn't rotated towards the white board (it could be because the z axis is causing the black face to not face the white board or the y axis could cause it to not face either)

alt text

The outcome is to only execute the logic if the entire black face of the object has collided with the white board.

I've also attempted to check if the entire surface of the collider has collided but I'm not getting anywhere with it, this rotation idea seems to be the most sensible I just can't seem to implement it.

I've tried looking at the objects Eular rotations but they don't seem to provide easily usable data.

The z goes from 0 to 90 or 360 to 270, then when it passes that mark it resets back to 0. Because ideally I was checking to see if the z Eular rotation was at 90' and the y Eular rotation was at 0' (the x rotation can be anything) which is how I was mocking up the idea changing the rotation properties in the editor.

But when I say "is the z = 90'" it isn't always 90' because if you rotate the x axis then the z axis will jump back to a different number.

I also tried using Quaternion numbers but I was totally lost :(

Does anyone have any ideas?

pic1.jpg (69.6 kB)
pic3.jpg (69.3 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Scribe · Apr 18, 2016 at 04:01 PM

How about doing it with vectors instead, that is, if the up direction of the cube is over a certain amount into the x direction, then if must mean the black side is facing nearly flat to the whiteboard. Here's a little example:

 Transform thisBlock;
 Vector3 desiredDirection;
 GameObject whiteboard;
 
 void Start(){
     thisBlock = this.transform;
 }
 
 void OnCollisionEnter(Collision c){
     if(c.gameObject != whiteboard) return;
 
     if(Vector3.Dot(desiredDirection, thisBlock.up) > 0.95f) return;
 
     //if we get here, remove collision detection or something?
     //as we hit the whiteboard but at the wrong angle
 }
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 Sysdia · Apr 18, 2016 at 04:20 PM 0
Share

Cool idea, thanks for that.

I think I've solved it by using transform.forward.x and transform.right.x

If transform.forward.x is 0 and transform.right.x is 0 then it's facing the right way

(it can also be facing the opposite way which is wrong but the white block will collide and the black side won't ever collide)

I'm just doing a few more tests to see if it works.

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

94 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

Related Questions

8-Pool Ball Keeps Rolling 2 Answers

Any ideas how I could slightly improve the Standard Assets car side collisions. 1 Answer

[RESOLVED] Two rigidbodies not colliding (even with traditional fixes, e.g. raycasting, collision detection) 2 Answers

Projectile Changing Angle BEFORE Impact 0 Answers

Getting 'bouyancy' on water to work. Help! 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