How do I make the curve less tall / how do I make the arc smaller?

Alright, I will try to keep this simple. Im making a basketball game. It is coming along great, and everything works. My only issue is this line of code right here:

local hrp = char.HumanoidRootPart

local Gravity = Vector3.new(0, -game.Workspace.Gravity, 0)
local x0 = hrp.CFrame * Vector3.new(0, 2, -2)
local Time = 1

local Velocity = (TargetPosition - x0 - 0.5*Gravity*Time*Time)/Time

Got the code from here

It works, and does generate an arc. The only issue is that the arc is SUPER high up. Im fairly close to the target position yet it flies super high and then down into the hoop. No other code is editing the velocity of the ball.

Is there a way to counteract how high it goes? Can I make it travel a smaller arc and still go above the TargetPosition a little? My idea was to use a BodyMover of some kind to make it go less high but I’m terrible with that kinda stuff.

So, my question is this: How do I make the curve less tall?

btw Im terrible with CFrames and math, I just was shown that as a code example and it worked fine for my situation, its just that the ball goes insanely high up.

1 Like

Im bad at math aswell, but try playing with the numbers, like the 0.5. Its what I always do :stuck_out_tongue:

Funny enough, I’ve messed with everything here except for that number I think. I’ll mess with it, see what it does.

Alright, I’ve come to a partial solution. The 0.5 does indeed dictate how much force is used when throwing the ball up. The problem? Now the ball can’t reach anything, at all. If it isn’t on .5, for some reason, it won’t reach the spot. Its too little force.

Alright, Try the y value in x0

Your issue is that time is always 1 in your code, so no matter how far or how close the target position is, it will take exactly 1 second to reach the target position. Instead you need to think of a max velocity you want to use and solve for time, instead of solving for velocity.

The best way to solve this issue is using kinematics equations

The y value does make it go higher, and with less force, it gives the desired effect. When close. Every other time it still never reaches the destination (My mouse cursor).

I’ve tried solving for time before by figuring out how close the player was. This did nothing unfortunately, the ball still flies really high in an arc :confused:

I probably did it wrong tho, I just calculated the distance, divided by like 10 or so and then added it to 1. It just made the ball travel even higher on a steep arc.

Have you tried playing with the Gravity number in this line, adding or subtracting from it?

local Gravity = Vector3.new(0, -game.Workspace.Gravity, 0)

I have. Still no difference from what it looks like :frowning:

What would be a good max velocity you thinking of for the basketball movement? like maybe 100 studs per second?

if so, then you would do
Time = distance/100

1 Like

Well, were off to a good start. The ball travels at a pretty consistent arc (except for when you are really far, but that doesn’t matter.) The problem is that it just isn’t quite making it to my mouse position. I have it on top of a part thats floating, and it hits the side of it. I tried editing with the y value of x0 again but it did nothing.

Well, I somewhat debugged the issue. When shooting from up close, the ball doesn’t even move in an arc anymore causing it to just hit the bottom of the part my mouse is on. A bit farther and it hits the side. Far away, it goes right where my mouse is.