Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Top Down shooter CharacterControl help?

Asked by 8 years ago

Hello! So I'm trying to make a top down shooter but my CharacterControls just don't seem to work. What I'm trying to do is make the character always face the mouses position. But I just doesn't seem to work. (This is taken off the roblox wiki (http://wiki.roblox.com/index.php?title=Top_Down_Action/Controls).

local player = game.Players.LocalPlayer
local gyro = nil
local mouse = player:GetMouse()
mouse.TargetFilter = game.Workspace.LevelGeometry
local runService = game:GetService('RunService')

local function onCharacterAdded(character)
    local torso = character:WaitForChild('Torso')
    gyro = Instance.new('BodyGyro', torso)
    gyro.P = 50000
    gyro.MaxTorque = Vector3.new(0, 10000, 0)
end

local function isnan(x) return x ~= x end

local function onRenderStep()
    if gyro then
        local mouseHit = mouse.Hit.p
        if not (isnan(mouseHit.X) or isnan(mouseHit.Y) or isnan(mouseHit.Z)) then
            gyro.CFrame = CFrame.new(player.Character.Torso.Position, mouseHit)
        end
    end
end

while not player.Character do wait() end
onCharacterAdded(player.Character)
player.CharacterAdded:connect(onCharacterAdded)

runService:BindToRenderStep('TrackMouse', Enum.RenderPriority.Input.Value, onRenderStep)

1 answer

Log in to vote
0
Answered by 8 years ago

I kinda fixed it by just commenting out line 4 Because I was getting an error that said "LevelGeometry is not a valid memeber of Workspace. I Think it said that because I din't have anything yet in that folder.

local player = game.Players.LocalPlayer
local gyro = nil
local mouse = player:GetMouse()
--mouse.TargetFilter = game.Workspace.LevelGeometry
local runService = game:GetService('RunService')

local function onCharacterAdded(character)
    local torso = character:WaitForChild('Torso')
    gyro = Instance.new('BodyGyro', torso)
    gyro.P = 50000
    gyro.MaxTorque = Vector3.new(0, 10000, 0)
end

local function isnan(x) return x ~= x end

local function onRenderStep()
    if gyro then
        local mouseHit = mouse.Hit.p
        if not (isnan(mouseHit.X) or isnan(mouseHit.Y) or isnan(mouseHit.Z)) then
            gyro.CFrame = CFrame.new(player.Character.Torso.Position, mouseHit)
        end
    end
end

while not player.Character do wait() end
onCharacterAdded(player.Character)
player.CharacterAdded:connect(onCharacterAdded)

runService:BindToRenderStep('TrackMouse', Enum.RenderPriority.Input.Value, onRenderStep)
0
If you solved it, delete the question. TheHospitalDev 1134 — 8y
0
Please don't delete this quetion. If other people encounter the same problem, they'll (hopefully) find this solution. XAXA 1569 — 8y
Ad

Answer this question