How to find legacy thumbstick input directions?

I’m currently scripting a vehicle to support mobile thumbstick input in addition to keyboard input. To do this, I used the :GetMoveVector() function from the player control script to map thumbstick input to one of four directions:

--assume this is all within a RenderStepped function
local MoveVector = Control:GetMoveVector()
if MoveVector ~= Vector3.new(0, 0, 0) then 
  if MoveVector.Z >= -1 and MoveVector.Z < 0 then
    print("Forward")
  elseif MoveVector.Z > 0 then
    print ("Back")
  elseif MoveVector.X >= -1 and MoveVector.X < 0 then
    print("Left")
  elseif MoveVector.X > 0 then
    print ("Right")
  end
end

Although this script functions as intended for the dynamic thumbstick, it doesn’t seem to work properly with the legacy thumbstick. These are the values :GetMoveVector() returns when I move forward ingame:
image
Dynamic thumbstick
image
Computer keyboard
image
Legacy thumbstick

Curiously, the legacy thumbstick returns movement vectors with absolute values greater than 1. This is the same case for every other direction. I’m at a bit of a loss here because this issue is unique to the legacy thumbstick. How can I get this script to map inputs from the legacy thumbstick without sacrificing support for keyboards/the dynamic thumbstick?

3 Likes

If you use math.clamp to force anything over/under 1/-1 to be 1/-1, does it work as intended? I’m not sure what going over 1 would actually signify, so making it function the same as 1 might be a bad idea (I don’t know). If that does work, it’d just be as simple as:

local x, y, z = math.clamp(MoveVector.X, -1, 1), math.clamp(MoveVector.Y, -1, 1), math.clamp(MoveVector.Z, -1, 1)
MoveVector = Vector3.new(x, y, z)
3 Likes

You could clamp, but the issue is that you could potentially lose the relative movement, so it might make a slight diagonal push into a much more diagonal one.

If you want to get a unit vector, so the magnitude is always 1 as it is with the other methods, then simply add .Unit to the MoveVector.

MoveVector = MoveVector.Unit

Sorry, I forgot I posted this a while ago. This fixed my issue though, thanks! I’ll mark this as solved soon.

1 Like