- Home /
Spawn 1-4 players around a Bezier curve?
I need to spawn 1-4 players at points around a bezier curve surrounding a basketball net (so around a 3-point line, essentially). This will be an AR environment, so there will be no actual 3-point line in the scene - I need a way to spawn a given number of players at equal distances from each other. So if there are 2 players, they will be placed at 10 and 2 of a clock-face. 4 players will be placed at roughly 9, 11, 1, and 3 of a clock-face.
Note: No player can be on the top of the oval (directly facing the net), as this would be an unfair advantage.
Answer by WarmedxMints · Mar 25, 2019 at 12:11 AM
You can get a point on the curve using this method;
public static Vector3 GetPointOnCurve(Vector3 startPoint, Vector3 midPoint, Vector3 endPoint, float t)
{
return Vector3.Lerp(Vector3.Lerp(startPoint, midPoint, t), Vector3.Lerp(midPoint, endPoint, t), t);
}
From there is just a matter of passing a value between 0 and 1 in the t parameter to get a point at the percentage you want the player to be.
yeah lerp maybe nice, but i think he need a reference for the half round curve placement.. along that line.
Answer by elenzil · Mar 25, 2019 at 06:42 PM
bezier curve is more complex, but if you want to choose points on an arc it's pretty simple.
// return a point on the unit circle lying in the XZ plane,
// uniformly distributed between degreesA and degreesB.
// "0 Degrees" is taken to be Vector3.forward, aka [0, 0, 1].
Vector3 PointOnArc(float degreesA, float degreesB) {
float deg = Random.Range(degreesA, degreesB);
return Quaternion.AngleAxis(deg, Vector3.up) * Vector3.forward;
}
I haven't actually compiled that, but it should work. Note you'll need to scale the result by the size of that semi-circle, and translate it by the center of the semi-circle.
Your answer
Follow this Question
Related Questions
Controlling roll rotation when travelling along bezier curves 1 Answer
Subdivide Bezier Curves 3 Answers
How to get lateral normals of a bezier curve 1 Answer
Circular curve using bezier formel 1 Answer
Cloud recognition in Vuforia 0 Answers