What do you want to achieve?
I’m trying to make a system in which the ball travels to any given position in an arc with a set time and height using physics and gravity.
What is the issue?
I’ve tried to make it using a modified version of the code used in Modeling a projectile's motion however changing the height/power causes the ball to travel over or past the position instead of through it. Increasing the power is meant to make the ball travel faster and increasing the height is meant to make the ball go higher. The ball also has a VectorForce that decreases the gravity force acting upon it.
What solutions have you tried so far?
As I previously mentioned, I’ve tried to make the system using a modified version of the code used in this post: Modeling a projectile's motion but the ball still travels too far or too high when the power and height values are changed.
The code I currently have:
while true do
wait(2)
local Clone = script.Ball:Clone()
Clone.Parent = workspace
Clone:SetPrimaryPartCFrame(workspace.Start.CFrame)
local Power = 80
local Height = 150
local Direction = workspace.End.Position - workspace.Start.Position
local Gravity = (Clone.Ball.Gravity.Force.Y + Height) - workspace.Gravity
local Duration = 1 - (Power / 100)
local Force = (Direction - 0.5 * Vector3.new(0, -Gravity, 0) * Duration * Duration) / Duration
Clone.PrimaryPart:ApplyImpulse(Force * Clone.PrimaryPart.AssemblyMass)
end
Any help would be appreciated.