I have a special bullet for my boss and I want to get the bullet to move in curves, but randomly and I’m not really sure how to achieve this.
Example Image
Something like that with the 2 coloured lines representing a path it could take. Basically, it would go from point A to point B in a curve but I want the points to be at random locations during the course of the game.
These bezier curve functions work pretty well; p0 and p1 are start and end points, c0 and c1 are random points you want it to curve past.
public static Vector3 BezierInterpolate3(Vector3 p0, Vector3 c0, Vector3 p1, float t) {
Vector3 p0c0 = Vector3.LerpUnclamped(p0, c0, t);
Vector3 c0p1 = Vector3.LerpUnclamped(c0, p1, t);
return Vector3.LerpUnclamped(p0c0, c0p1, t);
}
public static Vector3 BezierInterpolate4(Vector3 p0, Vector3 c0, Vector3 c1, Vector3 p1, float t) {
Vector3 p0c0 = Vector3.LerpUnclamped(p0, c0, t);
Vector3 c0c1 = Vector3.LerpUnclamped(c0, c1, t);
Vector3 c1p1 = Vector3.LerpUnclamped(c1, p1, t);
Vector3 x = Vector3.LerpUnclamped(p0c0, c0c1, t);
Vector3 y = Vector3.LerpUnclamped(c0c1, c1p1, t);
return Vector3.LerpUnclamped(x, y, t);
}