Hello i want to make a game like a basketball game. The Player should always make a basket with the basketball.
So this time i have a defined distance, a defined force value(AddRelative) and a defined throw-angle to make a basket. The basketbal has a rigidbody with gravity = true;
What i want to do is…if i change the distance to the basket…i want automatically calculate the throw angle and the force…
so that the player always can make a basket regardless of which distance to the basket.
Somebody has an idea how to calculate this please?
first I think one of the key components is to think if you are going to have a fixed height or not. If not perhaps height (how hi the ball goes ) is dependant on x distance to basket.
once you have x distance to basket and y height, you should be able to calculate some type of parabola that will allow for a basket to be made.
What you want to do is set the initial velocity of the basketball. This can be solved by first splitting up the motion into motion in the xz plane (which is not affected by gravity) and motion in the y axis (which is affected by gravity). As for motion in the xz plane, you know how far it is to the hoop, what direction it’s in, and you can decide what the initial velocity in the xz plane will be (the strength of the throw). With this you can know the time it will take to reach the hoop and this is important for calculating the initial y velocity.
For this use a UVATS equation:
U = initial velocity = unknown
V = final velocity = -1 (this is how fast the ball will be coming down)
A = acceleration = -9.81 (gravity)
T = time = 1 (we’ll just say this is how long it will take the ball to reach the hoop, you can calculate this as described above)
S = displacement = unknown
u = v - at
u = 1 - -9.811
u = 10.81
You might notice I negated the value of V (final velocity) in that calculation. This is to make sure you get the initial velocity required so the ball has the given final velocity on its way down. I’m not sure that negating V is sufficient to make that true, but I’m sure you or someone else can develop what I’ve done so far.
Also, instead of using the final velocity of the ball to adjust the parabola you can substitute a different UVATS equation and calculate the initial velocity by a target height instead.
@YosemiteSam: I’m trying to do the same thing as mikolo, but just can’t quite understand your formula. Is it possible for you to post more specifics on exactly how to do it? Or even better if you could make a sample pjt demonstrating how to make a sphere rigid body land into a hoop (allowing the launch position and the basket height to fluxuate), that would be really cool.