Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Top Down shooter CharacterControl help?

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

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)

2 comments

0

If you solved it, delete the question.

0

Please don't delete this quetion. If other people encounter the same problem, they'll (hopefully) find this solution.

This discussion is preserved as it was. New answers, comments, and votes are closed.