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
1
Question by Jackson93 · Feb 03, 2012 at 12:57 PM · rotationraycastnormal

how to find the normal of a side face from top view?

Hey all

This is my first post and i searched a lot however i could not find anything relating to my question. Basically I'm creating a top-down iPhone game, similar to a maze game, so I have the camera set to orthographic. For this game I want to have it so that when the user taps a wall, it instantiates 2 capsules either side of the wall. So far i have made a prefab with the two capsules contained in a empty game object and have gotten it to work on horizontal and vertical walls easily enough (this is shown in diagram A).

What i would like to do is make it so that wherever the user taps, it instantiates the prefab of capsules at the correct rotation even on a curved wall or pipe (diagram B). I am using a ray cast from the users tap so i have the point the tap hits the collider. I was thinking it might be possible to use the normal of the side face however not sure how to get this data as the face can not be hit with the ray cast. The only other alternative i can think of would be to have the wall in segments and rotate them inside unity (diagram c) so that i could use collider.transform.rotation but it would be so much better if it could work with any mesh.

Really appreciate any and all help. Im fairly good with code so all I'm really hoping for is a point in the right direction if anyone has any good ideas o has done this before.

Thanks in advance, Jackson.

alt text

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · Feb 03, 2012 at 04:35 PM

Obviously, it would have been easy with vertical and horizontal walls. As you seem to want circular walls as well, I don't think you can do without going down to the mesh. You can access the triangle hit by the ray with raycastHit.triangleIndex, then you might be able to find the faces you need, those with a normal having y = 0 and sharing vertices. I suppose you have walls not perfectly orthogonale to the ground.

So, not really a solution, but a lead I think.

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
0

Answer by Owen-Reynolds · Feb 03, 2012 at 04:58 PM

You could child empty "spawn points" to all your objects. Maybe add basePoints which are at expected tap points. On a tap, find the nearest basePoint. Each basePoint has two child spawn points. Or, just orient the basePoints, and always spawn at local +/-3X.

Or, if you don't want preset areas, you could still find the nearest basePoint and use the orientation to spawn from the tap point. Or, could use that as a guide for where to do a sideways rayCast from, to find the exact face to spawn from.

In theory, you can get that orientation data from the verts tangent's. Tangent is exposed in the Unity mesh interface, but not sure if the modelling program will set them the way you need.

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
0

Answer by Jackson93 · Feb 04, 2012 at 02:14 AM

Thanks for both your help. I haven't used the triangleIndex yet but i will have a go at that. If that doesn't really work for me I'll try using base points to guide the sideways ray cast.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cant understand why object rotates when setting transform.up to normal 2 Answers

Automatically rotating objects to fit on to others 0 Answers

default cylinder to indicate hit.normal 1 Answer

Why does the raycast hit only objects/faces of a certain rotation? 1 Answer

Rotating to match normal: Quaternion.FromToRotation(player.up, hit.normal) 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