THIS IS IN C#
So we know that a parabola is derived from the function y = x^2
so every point in a parabola starting from the center is equal to (x, x^2) because y is literally equal to x^2
so, how can we make this in unity?
1: create a float to serve as x
2: constantly change the position
so the first part is pretty straightforward:
float x = 0;
public GameObject theObject
where theObject is the object you want to move (you can just drag him in)
you can set x to anything, this is just the starting x point.
in the Start(), lets set the vertex to 0, just by setting the object’s position to (0,0,0)
theObject.transform.localPosition = Vector3.zero;
so the second part is actually also pretty easy: (in the update)
x += 0.05f;
theObject.transform.localPosition = new Vector3(x, Mathf.Pow(x, 2), 0);
Mathf.Pow is the easiest way to just make a float to the power of a number. the x += 0.05 is just the quantity that will change in x each time. meaning the smaller it is, the longer it is going to take and the smoother it will be
the reason i used localPosition is going to be explained in just a second
This above script will make the object go up.
if you wanted it to be flat on the ground and not change height, you would put the x in the Y position, and the x^2 in the Z position.
so if you wanted to change the positioning/rotation of it, your easiest solution would be just to make your object a child to an empty, and then move that empty around to your desired location (this is why i used localPosition, so it is relative to the parent)
of course, as far as customizing, you can change the x^2 to -x^2 (just making it negative) and it will go down
you can also change the starting position of the object by just changing x at its initiation, and you can also change the direction of the path (not the curve, that’s what would happen if i did -x^2) by doing x -= 0.05f instead.
if you wanted to make it fatter, you need to multiply the x^2 by something less than 1, but greater than 0
if you wanted to make it skinnier, you just need to multiply x^2 by something more than 1
you can always just tweak around with the stuff
this is all in global positioning, but really it’s basically just 2d in a 3d world.
have fun! hope I helped. If you have any more questions just ask