Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

How to find the closest 4 verts/corners ( along with their orientation ) of a rectangular object in relationship with another object?

$
0
0
Hi, In my game, the player object picks up and drops rectangular objects ( rects ). Before the player is allowed to pick up one of these rects, the rects need to have one face parallel with the x/z. If one face of the rect is parallel with the x/z then the player can pick up the object, but as the player moves into position, it needs to rotate on the y axes and extend or retract it's arms so the player object's corners align with the closest 4 corners/verts of the rect ( highest verts on the y axes ). For finding out if the rects are sitting flat with one face parallel with the x/z axes, renderer.bounds.size.y seems to give good results because the rects are 3x3x6, so it will give me 3 or 6 if it is flat. Please let me know if that is bad practice. For finding out the closest 4 corners/verts and the y rotation that the player object would have to assume to line up with the 4 verts, I was thinking of using mesh.vertices to find the certs with the highest y value and calculating the angle between them to attain the y rotation needed for alignment, but is there a more standard way to do something like this without making extra child game objects for each corner of the rects??

Viewing all articles
Browse latest Browse all 171066


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>