Hi. I was recently provided with a script for a swipe system where you swipe the ball and it rolls. But I have a question: where do I put it and where do I get it from in Workspace ScreenGui if it’s not there? Please explain.
function onMouseMove(x, y, dx, dy)
local speed = math.sqrt(dx * dx + dy * dy)
local direction = math.atan2(dy, dx)
game.Workspace.Ball:ApplyForce(Vector3.new(speed * math.cos(direction), 0, speed * math.sin(direction)))
end
game.Workspace.ScreenGui.MouseMoved:Connect(onMouseMove)
I can assure you that the script does not work due to some methods not existing. It was probably written by ChatGPT if I’m not wrong.
However, the calculations seem to be correct. You will want to replace this:
with something else like this:
game:GetService("UserInputService").InputChanged:Connect(function(iObj, ignore)
if ignore then return end
if iObj.Position.Magnitude == 0 then return end
local v2Pos = Vector2.new(iObj.Position.X, iObj.Position.Y)
local v2Delta = Vector2.new(iObj.Delta.X, iObj.Delta.Y)
onMouseMove(v2Pos.X, v2Pos.Y, v2Delta.X, v2Delta.Y)
end)
Untested. Point out any errors with this script.
(should also work with mouse movement too)
Then, you need to replace the apply force with ApplyImpulse. Keep in mind you might need to multiply the force.
To answer your original question, the script will be a local script in any container, but I recommend StarterPlayerScripts.
I don’t know if I understood you correctly, but that’s what I did.
function onMouseMove(x, y, dx, dy)
local speed = math.sqrt(dx * dx + dy * dy)
local direction = math.atan2(dy, dx)
game.Workspace.Ball:ApplyImpulse(Vector3.new(speed * math.cos(direction), 0, speed * math.sin(direction)))
end
game:GetService("UserInputService").InputChanged:Connect(function(iObj, ignore)
if ignore then return end
if iObj.Position.Magnitude == 0 then return end
local v2Pos = Vector2.new(iObj.Position.X, iObj.Position.Y)
local v2Delta = Vector2.new(iObj.Delta.X, iObj.Delta.Y)
onMouseMove(v2Pos.X, v2Pos.Y, v2Delta.X, v2Delta.Y)
end)
Actually, it does work, but you need to set the camera properly and all that stuff. You first need to set the network owner of the ball. Then, you need to use the mouse delta, which is holding right click or dragging.