I’ve been trying to replace [A] and [D] with camera movement similar to the [ LEFT ] and [ RIGHT ] arrowkeys, basically DooM movement. But I’ve been unable to. I’ve found that people edit the player module, but I’d like to customize this movement, [ AKA, make the camera movement choppy, make it so you can look up and down using keys at some point, etc ] and since the player module is just too complex for me to edit anyway, it’s out of the question. if anyone has any tips or ideas that can help me, please let me know. any help is greatly appreciated!
P.S, I’ve tried looking around on devfourm, checked toolbox, tried finding open source games, and even tried to use ai, I’ve also looked a bit on youtube just now and haven’t found a single resource on how to make this. so can someone please help me? thanks!
Hello,
this isn’t much of help , but here’s script that probably replicates what you want, put it inside StarterPlayerScripts PlayerModule.rbxm (140,6 KB)
If you want to find out whats going on you can search inside the script for Enum.KeyCode.A and Enum.KeyCode.E inside CameraInput script
Thanks for the response and the help! sadly while this does give the desired result to some extent, it uses the player module which is difficult to edit as there’s so many lines of code/scripts. I’d have no clue where to start on editing it to get my desired effect [ aka, chopping camera, etc ], and it’s a bit to advanced as someone who’s still pretty unknowning about camera related coding. but thanks for the help!
Another method would be using this inside localscript
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
workspace.CurrentCamera.CFrame *= CFrame.Angles(0,math.rad(30),0)
end
end)
hey thanks! that’s actually a big help, anytime I’d try to rotate the camera before it’d just kinda move weirdly. is there anyway to switch it from press to hold? I know you could most likely use values but in my own time using coding, I’ve found that values tend to be unreliable, or maybe I’m just using them wrong.
p.s, what does math.rad do? why use it? I’ve made a script like this before but without the math.rad, and it’d rotate like it was orbiting a planet instead of a straight line.
math.rad(90) prints always 1.57…
math.rad(360) prints always 6.28
since your not adding values like + , it’s better to use * math.rad()
If you use math.rad(180) you will notice it prints out “pi”, since it’s used for rotation. circles thing
Anyway since you wanted to see if it works with KeyDown etc,
local keyboardState = {
Left = 0,
Right = 0
}
local IPS = game:GetService("UserInputService")
local Task
function update()
while true do
workspace.CurrentCamera.CFrame *= CFrame.Angles(0,math.rad(0+keyboardState.Left+keyboardState.Right),0)
wait(.2)
end
end
function updateTask()
if Task then
pcall(function()
task.cancel(Task)
Task = nil
end)
end
Task = task.spawn(update)
end
local function keypress(action, state, input)
if input.KeyCode == Enum.KeyCode.A then
keyboardState.Left = state == Enum.UserInputState.Begin and 45 or 0
end
if input.KeyCode == Enum.KeyCode.D then
keyboardState.Right = state == Enum.UserInputState.Begin and -45 or 0
end
updateTask()
end
--game:GetService("UserInputService").InputChanged:Connect(keypress)
local CTX = game:GetService("ContextActionService")
CTX:BindAction('KeyDownThing',keypress,false,Enum.KeyCode.A,Enum.KeyCode.D)
woah that’s sick, it’s clearly advanced but also readable so I can understand it, thanks! how does it detect you’re holding it down when I don’t see anything increasing the value of left/right? I’m used to seeing code increase a value so it knows
The code is doing it over
math.rad(0+keyboardState.Left+keyboardState.Right)
Which is manipualted down here
keyboardState.Left = state == Enum.UserInputState.Begin and 45 or 0
It’s basically InputBegan and InputEnded, just cut down by using ContextActionService.
I still don’t quite follow, why have the local keyboardstate if it doesn’t seem to change the value? or am I misunderstanding the code and it’s changing the value in some way I don’t get?
don’t be sorry, it works great and shortens the code! and it gets the job done! it’s just I’ve never seen anyone use it before and I’m new to scripting, so it’s interesting to me [ interesting as in, unique, and something I haven’t seen done before ]
and will do! I think I have everything I need to make something out of it! thanks!