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?
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.
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
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.
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.