I am currently looking for a way to tell which way I am moving. However, the solutions i have tried (like Humanoid.MoveDirection) all don’t achieve what I need. What I need is data in a Vector3 that tells me if my player character is moving left, right, back, or forward. Does this data exist? If not, how would I code it into existence? Thanks!
try this “Humanoid.RootPart.AssemblyLinearVelocity.Unit”
You will get the Unit Vector (Vector3) move direction of the player
It should? It returns exactly what you want.
You should combine Humanoid.MoveDirection with the direction that the character is facing to find out the relative motion of the player. If you need an example, let me know.
I think they are looking for the relative direction, not the absolute direction.
Try MoveDirection along with this.
function cardinalConvert(dir)
local angle = math.atan2(dir.X, -dir.Z)
local quarterTurn = math.pi / 2
angle = -math.round(angle / quarterTurn) * quarterTurn
local newX = -math.sin(angle)
local newZ = -math.cos(angle)
if math.abs(newX) <= 1e-10 then newX = 0 end
if math.abs(newZ) <= 1e-10 then newZ = 0 end
return Vector3.new(newX, 0, newZ)
end
This is ALMOST exactly what I need, but it shows the same problem I’m having. For detail, my problem is that, for example, facing left and walking left (A key) produces, let’s say a 1. But turning around to face right and walking left (A key) would produce a -1. I want a way to know if I’m pressing A, D, W, S, etc. all in a neat Vector3 value.
Maybe focus on the last key they pushed. Idk, not all movement will totally show direction.
I think I understand what you need. You can get the raw input moveVector by calling the ControlModule:GetMoveVector(). This function can be found in PlayerModule.ControlModule
-- Convenience function so that calling code does not have to first get the activeController
-- and then call GetMoveVector on it. When there is no active controller, this function returns the
-- zero vector
function ControlModule:GetMoveVector(): Vector3
if self.activeController then
return self.activeController:GetMoveVector()
end
return Vector3.new(0,0,0)
end
Make a copy of the PlayerModule during runtime and paste it back into StarterPlayerScripts ,
then from there you can access the roblox default ControlModule by requiring the module.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.