How to difine an point on mash

If i have box whit corner points A,A1, B,B1, C,C1, D,D1

So how to define example point A of the mesh so i can set raycast point to the A point or how to define any point on mash to use it in scripting?
Sorry if too noob question i tryed to find answer whit search but dident have luck

2 Answers

2

The easiest solution is to put empty game objects at the points you care about and make them a child of the cube. You can then reference these objects no matter how the object is resized to get the position.

It can be done mathematically. You define your point on the original cube. Given your indicator, ‘A’ is on the front size of the cube, so point A would be (0.5, -0.5, 0.5). You then transform this point into world space:

 var worldPos = transform.TransformPoint(Vector3(0.5, -0.5, 0.5));

Point C is (-0.5, -0.5, 0.5), and the position between the two (0.0, -0.5, 0.5).

Given two world positions you can find the point between them by:

 var between = (v1 + v2) / 2.0; 

…or:

 var between = (v2 - v1) / 2.0 + v1;

Ty i think i got it i needed TransformPoint other math stuff i knowed but anywey ty again

If you didn’t create this mesh by code yourself, you will have to access the mesh’s vertices array and see which Vector3 inside is the one you want to use as your RayCast origin.

As for the middle point between A and C, you could use Vecto3.distance between the two, then use the 1/2 of this value and add it to A’s x position. Of course, it gets more complicated if the mesh is rotated etc. but the principle remains the same.