Hello! Recently I’ve been struggling trying to figure out how I could make a swipe system: basically a system where you swipe with your mouse in a direction in 2D space, and then I take that and translate the direction into 3D space and then set velocity to a ball in said direction. This turned out to be harder than anticipated, I’ve tried numerous methods but still haven’t much luck. I do have some code here below, if anyone would have the time to try to see what I could do differently. One other note, the code below does work. However, the ball doesn’t always go in the right direction, which I’m trying to perfect somehow. Thanks for reading!
local Camera = game.Workspace.CurrentCamera local Start = game.Workspace:WaitForChild("Cam_Part") local End = game.Workspace:WaitForChild("End") local mouse = game.Players.LocalPlayer:GetMouse() local uis = game:GetService("UserInputService") local db local mdown = false local ball = workspace.ball Camera.CameraType = Enum.CameraType.Scriptable Camera.CFrame = Start.CFrame function begin_swipe() local start_ = Vector2.new(mouse.X,mouse.Y) while mdown do wait() end local dist = (Vector2.new(mouse.X,mouse.Y) - start_).magnitude / 5 if dist > 40 then local ray_ = mouse.UnitRay.Direction local diff = (ray_ - ball.Position).unit ball.Velocity = diff * 25 end db = false end