Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how to use velocity in two axes at the same time (X and Y axis) ?

Hello, I would like to know how to use velocity in two axes at the same time (X and Y axis), the idea of this is that when a ball collides with the box the ball is thrown with the velocity in the X and Y axis.

How could I do that?

1 answer

You can use body movers.

local debris = game:GetService("Debris")

box.Touched:Connect(function(partTouched)
	if partTouched == ball then
		local bodyVelocity = Instance.new("BodyVelocity",ball) --create a body velocity and parent it to the ball
 		bodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge) -- Determines the limit on how much force that may be applied to each axis
		bodyVelocity.P = 1000 -- Determines how aggressive of a force is applied in reaching the goal velocity
		bodyVelocity.Velocity = ball.CFrame.lookVector * 100 + Vector3.new(0,50,0) -- make the goal of the velocity 100 studs out from where the ball is looking and up 50 studs.
		debris:AddItem(bodyVelocity, 0.5) -- deletes the bodyVelocity after 0.5 seconds. You can adjust this value and the other values above to your liking
	end
end

If you have any issues let me know.

This discussion is preserved as it was. New answers, comments, and votes are closed.