I am trying to make a “custom movement” system. It is meant to simply let you change directions instantly mid air through the use of HumanoidRootPart.Velocity . It uses the movement detection in PlayerModules to detect movement.
The problem I am having is with the maths. It is a pretty silly thing to post about however I am lost as to how I can fix it. The script mainly uses 3 parameters.
One is the magnitude (basically defining the speed / what the final velocity is multiplied by.) The player’s CFrame.LookVector and finally the direction of the pressed button.
Expanding on the last parameter it is a vector3 value which is determined as seen below
--[[
N
NW NE
W E
SW SE
S
]]--
local E = Vector3.new(1,0,0)
local W = Vector3.new(-1,0,0)
local N = Vector3.new(0,0,-1)
local S = Vector3.new(0,0,1)
local NW = N + W
local NE = N + E
local SE = S + E
local SW = S + W
^^ These are sent to the serverscript as “dir” and are chosen by controlModule:GetMoveVector()
This is the math for the velocity
local replicatedStorage = game:GetService("ReplicatedStorage")
local movementEvent = replicatedStorage:WaitForChild("Movement")
local runService = game:GetService("RunService")
local mag = 40
movementEvent.OnServerEvent:Connect(function(player, veloPart, dir)
runService.Heartbeat:Wait()
local lookVec = veloPart.CFrame.LookVector
local final = (mag * dir)
print(final)
if dir ~= Vector3.new(0, 0, 0) then
veloPart.Velocity = final
end
end)
I have tried the obvious dir * LookVector but got a weird phenomenon. As simple as I can describe it is depending on the way you look the different keys made the character go different ways. (Not random but weird.)
I have also tried dividing, adding, subtracting, modding ("%" , just gave an error, not even sure what it does.)
Any other extra information I could give:
If the character is stationary the vector3 given is simply 0,0,0.
The movement speed is set to 0 but this does not effect the detection.
Jumping is pretty crooked but I intend to fix that later.
Hopefully I was as descriptive as I need to be and thanks in advance.
Edit: Fixed some spelling. Sorry