x


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

more ▼

asked Feb 03 '12 at 12:57 PM

Jackson93 gravatar image

Jackson93
16 1 1 1

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Feb 04 '12 at 02:14 AM

Jackson93 gravatar image

Jackson93
16 1 1 1

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Feb 03 '12 at 04:35 PM

Berenger gravatar image

Berenger
11k 12 19 53

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Feb 03 '12 at 04:58 PM

Owen Reynolds gravatar image

Owen Reynolds
11.2k 1 7 45

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2155
x1525
x124

asked: Feb 03 '12 at 12:57 PM

Seen: 528 times

Last Updated: Feb 04 '12 at 02:14 AM