Hello, this is my first post but im a new dev making a new game about 8ball and snooker and ive made a simple start where you can hit the ball, ive figured out the physics and the pool table but im stuck on how i would make a cue work,
i want to make it so the cue has collitions of annd would circle around the cue ball when i circle round it with my camera and when i press the shoot button it plays a animation and that all i need but i cant seem to fint any tutorials on how to start so im a little stuck, this is what i have so far in the game:
and here is the code for the circling
local targetObject = game.Workspace.Balls:FindFirstChild("CueBall") -- Replace "TargetObject" with the actual name of the object you want the camera to follow
local camera = game.Workspace.CurrentCamera
local UserInputService = game:GetService("UserInputService")
local db = true
local cameraDistance = 10
local cameraAngleX = 0
local cameraAngleY = 45
local isFollowingCueBall = true
local sensitivity = 0.2
local baseSensitivity = 0.03
local rotationSpeedX = 0
local rotationSpeedY = 0
-- Calculate the initial position only once outside the functions
local initialPosition = targetObject and targetObject.Position
local function updateCamera()
if targetObject and initialPosition then
rotationSpeedX = rotationSpeedX - (rotationSpeedX * 0.15)
rotationSpeedY = rotationSpeedY - (rotationSpeedY * 0.15)
cameraAngleX = math.clamp(cameraAngleX - rotationSpeedX * sensitivity, -45, 0)
cameraAngleY = cameraAngleY - rotationSpeedY * sensitivity
local rotatedCFrame = CFrame.Angles(0, math.rad(cameraAngleY), 0) * CFrame.Angles(math.rad(cameraAngleX), 0, 0)
local cameraPosition = initialPosition + (rotatedCFrame.LookVector * -cameraDistance)
local lookAtPosition = initialPosition
camera.CFrame = CFrame.new(cameraPosition, lookAtPosition)
end
end
local function rotateCamera()
local mouseDelta = UserInputService:GetMouseDelta()
rotationSpeedX = rotationSpeedX + mouseDelta.Y * sensitivity
rotationSpeedY = rotationSpeedY + mouseDelta.X * sensitivity
updateCamera()
end
local function onShiftPressed()
sensitivity = baseSensitivity
game.Players.LocalPlayer:FindFirstChild("PlayerGui"):FindFirstChild("PowerBarGUI"):FindFirstChild("aim").Visible = true
end
local function onShiftReleased()
sensitivity = 0.2
game.Players.LocalPlayer:FindFirstChild("PlayerGui"):FindFirstChild("PowerBarGUI"):FindFirstChild("aim").Visible = false
end
game:GetService("RunService").RenderStepped:Connect(rotateCamera)
-- Listen for Shift key press and release events
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
onShiftPressed()
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
onShiftReleased()
end
end)
local RemoteEvent = game.ReplicatedStorage.hi
RemoteEvent.OnClientEvent:Connect(function()
if targetObject then
initialPosition = targetObject.Position
updateCamera()
end
end)