Hi,

I already researched a lot but none of the solutions that i can find seem to work. The distance between p0 and p2 is decided by how far the MousePosition (p2) is away from p0. Yet, how would i make it so that, no matter what the distance is, it always takes the same time (say for example, 5 seconds) to get from p0 to p2?

function quadBezier(t, p0, p1, p2)
	return (1 - t)^2 * p0 + 2 * (1 - t) * t * p1 + t^2 * p2
end

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local speed = 50

Mouse.Button1Down:Connect(function()
	local p0 = Character.PrimaryPart.Position + Vector3.new(0,3,0)
	local p2 = Mouse.Hit.p
	local p1 = p0:Lerp(p2, .5) + Vector3.new(0,5,0)

	local snowball = workspace.snowball:Clone()
	snowball.Parent = workspace 

	coroutine.wrap(function()
		for t = 0, 1, 1/100 do
			local newPos = quadBezier(t, p0, p1, p2)
			snowball.Position = newPos
			wait()
		end
	end)()

end)

I'm trying to make a snowball. Thanks in advance!

1 comment

0

Using the speed, distance & time pyramid, you can find that time = distance/speed. Example, there are 3 points: A, B and C. A and B are 10cm apart, B and C are 20. Travelling at 10cm/s, we can say that the time taken to travel from A to B is 10/10 = 1 second. And B to C is 20/10 = 2 seconds. We can also flip the equation around to get Speed = Distance/Time and Distance = Speed * Time