Hello!
I’ve been trying at the issue for a while and I don’t see a foreseeable solution - atleast in my eyes.
I have made a mortar system in which you move your mouse, while in first person, left, right, up, or down and the mortar will follow. You do this while locked in first person and viewing through the mortar’s scope, which is a part. I track the mouse movement and determine which way it’s moving like so:
if math.abs(Mouse.X - lastMouseX) > math.abs(Mouse.Y - lastMouseY) then
if Mouse.X - lastMouseX > 0 then
Mortar.MortarComputer.Adjust:FireServer(Mortar, -.1)
else
Mortar.MortarComputer.Adjust:FireServer(Mortar, .1)
end
else
if Mouse.Y - lastMouseY > 0 then
Mortar.MortarComputer.Adjust:FireServer(Mortar.Barrel, .1)
else
Mortar.MortarComputer.Adjust:FireServer(Mortar.Barrel, -.1)
end
end
I’m running into the issue where the player runs out of screen room to move the mortar all the way. I can’t track the rotation of the camera, as they are locked to a part and are in first person. I’m honestly out of ideas and would love some feedback so I could finish this.
Thanks for any help.
I’m not entirely sure what you’re doing in your script but I think you’re having trouble with your camera being locked because its first person. You should know that if you want to change the position of the players camera, you can access their camera inside of workspace.
game.Workspace.CurrentCamera
in a local script. You can only do this in a local script.
you can simply say:
game.Workspace.CurrentCamera.CFrame = (insert cframe)
but you have to change the cameratype to scriptable so that the camera isnt affected by roblox’s built in scripts (like first person)
so the script is like:
game.Workspace.CameraType = "Custom"
task.wait(.1)
game.Workspace.CurrentCamera.CFrame = CFrame.new() * CFrame.Angles()
you are able to change the rotation from the CFrame as well as the camera position. If you don’t know how, go here
Here’s the entirety of my script and I already implement what you suggested into my script.
wait()
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Mortar = script.Mortar.Value
local lastInputTime = tick()
local Playing = false
local lastMouseX, lastMouseY = Mouse.X, Mouse.Y
function roundNumber(num, numDecimalPlaces)
return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end
--Player.CameraMode = Enum.CameraMode.LockFirstPerson
UserInputService.MouseIconEnabled = true
RunService.RenderStepped:Connect(function()
if tick() - lastInputTime > 1 and Playing == true then
Mortar.MortarComputer.Tech:FireServer(false)
Playing = false
end
game.Workspace.Camera.CameraSubject = Mortar.Barrel.Sight.Camera
game.Workspace.Camera.CFrame = Mortar.Barrel.Sight.Camera.CFrame
game.Workspace.Camera.CameraType = Enum.CameraType.Scriptable
end)
Mouse.Move:Connect(function()
script.Parent.Elevation.Text = roundNumber((Mortar.Barrel.Barrel.Orientation.Z) * -17.45, 2)
script.Parent.Deflection.Text = roundNumber(Mortar.PrimaryPart.Orientation.Y, 2)
Mortar.MortarComputer.Tech:FireServer(true)
lastInputTime = tick()
Playing = true
if math.abs(Mouse.X - lastMouseX) > math.abs(Mouse.Y - lastMouseY) then
if Mouse.X - lastMouseX > 0 then
Mortar.MortarComputer.Adjust:FireServer(Mortar, -.1)
else
Mortar.MortarComputer.Adjust:FireServer(Mortar, .1)
end
else
if Mouse.Y - lastMouseY > 0 then
Mortar.MortarComputer.Adjust:FireServer(Mortar.Barrel, .1)
else
Mortar.MortarComputer.Adjust:FireServer(Mortar.Barrel, -.1)
end
end
lastMouseX, lastMouseY = Mouse.X, Mouse.Y
end)
Any other ideas on how I could solve this problem? Thanks for responding.
1 Like