Hey! I’m super tired and I can’t figure this out. Nor can I figure out a good way to title this post! What I’m looking for is essentially just to get movedirection as if my camera was never rotated. You can see in game, it translates to -1 to 1 on x and -1 to 1 on z. The moment you rotate your camera slightly, it gives an approximation to the direction you’re going in based on where you’re going in the world.
What I’m trying to do is to just get this move direction without the “direction”, which is to say if you press “A” it should return (-1, 0, 0), and if you press “SD” it should return (0.5, 0, -0.5) (or something like this)
I do realize this post is poorly described as I am extremely tired. I’m gonna go sleep now, but if someone gets what I’m trying to ask and knows how to do it please let me know!
ps: Simply reading for the key presses is out of the question. I’m trying to add controller and phone support, after all.
" ps: Simply reading for the key presses is out of the question. I’m trying to add controller and phone support, after all."
Not exactly what I need, but you got the right idea for what I’m trying to do.
Well u could still use those but instead just use up down left right states then have them interpolate to 1 then multiply them so that you get this motion you describe
As far as I know roblox doesn’t have any direct movement input that is shared across keyboard/touchscreen/controller. Movedirection is the closest thing we have to this (as far as I am aware), and therefore is the only thing I can use in this case.
Well maybe I should have clarified. You have 2 inputs right? If they are holding their thumb left or right? Simply increment it to its maximum value based on how long they are holding it (the acceleration)
That seems like an incredibly overcomplicated janky solution to this. Let me reiterate: Trying to use controls directly is out of the question. I’m not gonna add 100+ lines of logic to account for every single input type at every moment for a very niche situation in my game.
You can get this value from the default player module control script.
local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts.PlayerModule)
local Controls = PlayerModule:GetControls()
print(Controls:GetMoveVector())
Yep, just needed a few changes for it to round properly:
local v = self.ControlModule:GetMoveVector()
local vunit = v.unit
local absx = math.abs(vunit.x)
local absz = math.abs(vunit.z)
absx = absx > 0.1 and absx or 0
absz = absz > 0.1 and absz or 0
local inputdir = v * Vector3.new(absx, 0, absz)
.unit-ing it directly doesn’t work because otherwise it loses the ability to tell you analog input, and without the above 0.1 check it returns NaN when not pressing a key.