I am experimenting with an angry birds type game and was wondering if I could have some help with the slingshot function.
Here is a picture of what I currently have set up
My current idea was to use the mouse position and apply it to the position, like this:
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local mainPart = workspace:WaitForChild("Main")
local setPosition
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Mouse Began")
setPosition = RunService.Heartbeat:Connect(function(dt) --starts loop
mainPart.Position = Vector3.new(mouse.X, mouse.Y, mainPart.Position.Z) -- tries (and fails) to set parts position relative to the mouse and the same Z axis
end)
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Mouse Ended")
setPosition:Disconnect() --disconnects loop
end
end)
Currently whenever I try it, it just goes in a seemingly random direction. I have also tried math.clamp, but to little avail as it is in a loop so it just keeps passing the clamp and then setting a new one just to get passed again (that was a horrible explanation).