How can I throw an object further?

How can I allow for the dice to be thrown with more power?

Here’s the code I currently have:

local gyro = Instance.new("BodyGyro")
gyro.Name = "Gyro"
gyro.Parent = DiceObject 
gyro.MaxTorque = Vector3.new(500000, 500000, 500000)
local force = Instance.new("BodyPosition") 
force.Name = "Force" 
force.Parent = DiceObject
force.MaxForce = Vector3.new(10000, 10000, 10000)
mouse.TargetFilter = DiceObject

local camera = workspace.CurrentCamera 
mouse.Icon = "rbxasset://textures/advClosed-hand.png"
DiceObject.Position = camera.CFrame.Position + (DiceObject.Position.Unit * 20)
UserInputService.InputBegan:Connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
		Held = true
		mouse.TargetFilter = DiceObject
		mouse.Icon = "rbxasset://textures/advClosed-hand.png"
	end
end)
UserInputService.InputEnded:Connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
		Held = false
		mouse.Icon = "rbxasset://textures/advCursor-openedHand.png"
		if DiceObject then
			if DiceObject:FindFirstChild("Gyro") or DiceObject:FindFirstChild("Force") then
				DiceObject.Gyro:Destroy() 
				DiceObject.Force:Destroy()
			end
		end
	end
end
game:GetService("RunService").RenderStepped:Connect(function()
	if Held == true and DiceObject ~= nil then 
        DiceObject.Gyro.CFrame = DiceObject.CFrame
		DiceObject.Force.Position = camera.CFrame.Position + (mouse.UnitRay.Direction * 20)
	end 
end)

The dice model does not go very far, and I feel like it just drops.
Do I need to apply a force when the mouse releases? If so, which one? How can I make it feel like the player is throwing the dice?

3 Likes

Try amplifying this line:

DiceObject.Force.Position = camera.CFrame.Position + (mouse.UnitRay.Direction * 20)

To something like this:

DiceObject.Force.Position = camera.CFrame.Position + (mouse.UnitRay.Direction * 20) * 50
2 Likes

That caused it to go flying extremely fast out of view. Even just multiplying it by 2 does this as well.

That’s because the body position’s position is being multiplied so it wants to go further to where the camera and mouse direction is. Try multiplying the dice’s velocity or rot-velocity and see if that does anything.

1 Like

I was able to make it move further/with more power using BodyForce.

Is there a way I can make this speed vary depending on how fast the mouse is moving?

1 Like

You can do that by tracking the mouse’s position on the screen using
Vector2.new(mouse.X, mouse.Y)
then comparing distances over time to get your speed
PS be sure to use magnitude

1 Like

Where would I get the first vector from? I know I can get the second one when the client releases. Not sure where to get the first one, though.

1 Like

That can depend on your preferences and trial and error but you mostly want it close to where you release it but not so close that it can mess up the speed so your going to want to update it at 1-0.5 second rate you can check by using tick() in the part of the script that has the dice following the mouse. you can also multiply that if you feel its to weak but it is going to take some messing around to get.

1 Like

Got it! Thanks for the help. My main concern with that is that it updates at the same time the player releases the mouse, but I’m sure I can play around with it.

Hm try making relovelocity 46 or animate something for the dice.

1 Like

You can save 3 values so if it updates too close you can use the 3rd value to calculate

1 Like

Here’s a somewhat finished product. I’m still working things out but I’m happy with it!

1 Like