- Home /
Question is off-topic or not relevant
How do i create objects in between two points with an offset???
Hello i am wondering on how to do this
in Pic1 SEG3, for example i know how to do whats in SEG1/SEG2 with this
Vector3 position = controlPoints[i].position + j *(controlPoints[i + 1].position - controlPoints[i].position) / segCount;
(For more about the code visit here its an old question i asked about dividing between two points), but i want to know how to do this in SEG3(which we'll come around in second), as you can see in SEG2 when i move it the subPoints will always stay in the center, but i want to know when i move it like in SEG3 that sub points stay specific distance(int distanceCP) away from the controlPoints, would anyone know how to do this??
-Pic1
Here is the code that does SEG1/SEG2.
public class Points : MonoBehaviour
{
public Transform[] points;
public GameObject GameObj;
public float GameObjectAmount = 2;
void Start()
{
duplicateObject(GameObj, (int) GameObjectAmount);
}
public void duplicateObject(GameObject original, int howmany)
{
howmany++;
for (int i = 0; i < points.Length-1; i++)
{
for (int j = 1; j < howmany; j++)
{
Vector3 position = points[i].position + j * (points[i + 1].position - points[i].position) / howmany;
Instantiate(original, position, Quaternion.identity);
}
}
}
void OnDrawGizmos()
{
for (int i = 0; i < points.Length - 1; i++)
{
Gizmos.DrawLine(points[i].position, points[i + 1].position);
}
}
}
Answer by Benjames · Sep 06, 2016 at 03:54 AM
Vec1+(Vec2-Vec1).normalized*distance == what you want I think
Thanks-ish @Benjames but it did not work correctly as you can see in Pic1 SEG1 is what i get, i'm trying to do this in SEG2.
NOTE: I made a mistake in the picture the top one is SEG1
-Pic1 Don't $$anonymous$$d the white spheres in SEG2 i was supposed to erase them
And this is the code i changed.
Vector3 position = points[i].position + j * (points[i + 1].position - points[i].position) / howmany;
To
Vector3 position = points[i].position + (points[i].position - points[i + 1].position).normalized * 1f;
EDIT: Look at the post i edited the picture.
Vector3 position = points[i].position + (points[i+1].position - points[i].position).normalized * 1f;
Benjames' code looks correct, you just had the point order wrong.
@doublemax Either way of the point order It still does not get me what i want, i am getting this as you can see in Pic1 with the code, ins$$anonymous$$d of this in Pic2.
Are you referring to the fact that there is only one sphere and the one at the other end is missing? For that one you just have to swap the points in the formula and do it again.