i am trying to make serversided movement, but i have a problem that the character keeps rotating that if it example falls off something (spawn location) it will rotate itself to face the ground, so how do i disable it?
--local engine = require(game.ReplicatedStorage.Engine)
local vector3 = {
["X"] = 0,
["Y"] = 0,
["Z"] = 0,
}
function vector3.new(x, y, z)
local v3 = vector3
x = tonumber(x) or 0
y = tonumber(y) or 0
z = tonumber(z) or 0
v3.X = x
v3.Y = y
v3.Z = z
return v3
end
function vector3:back()
return Vector3.new(self.X, self.Y, self.Z)
end
vector3.zero = vector3.new()
local player = {
["base"] = nil,
["keys"] = {},
["wishmove"] = vector3.zero,
["vel"] = vector3.zero
}
PLAYERS = {
}
function processKeys(keys)
local forward, back, left, right, xm, zm, jump
forward = nil
back = nil
left = nil
right = nil
jump = 0
if table.find(keys, Enum.KeyCode.W) then
forward = 1
end
if table.find(keys, Enum.KeyCode.S) then
back = 1
end
if table.find(keys, Enum.KeyCode.A) then
left = 1
end
if table.find(keys, Enum.KeyCode.D) then
right = 1
end
if table.find(keys, Enum.KeyCode.Space) then
jump = 1
end
if forward and back then
zm = 0
elseif forward and not back then
zm = 1
elseif not forward and back then
zm = -1
else
zm = 0
end
print(zm)
if left and right then
xm = 0
elseif left and not right then
xm = 1
elseif not left and right then
xm = -1
else
xm = 0
end
local move = vector3.new(xm, jump, zm)
return move
end
local function findp(n)
for i,v in PLAYERS do
if v[1] == n then
return v[2], i
end
end
end
game.ReplicatedStorage.C2S.Key.OnServerEvent:Connect(function(p, key, startedHold)
local playerindex, _ = findp(p.Name)
local thisKeyExists = table.find(playerindex.keys, key) ~= nil
if startedHold and not thisKeyExists then
table.insert(playerindex.keys, key)
else
if thisKeyExists then
table.remove(playerindex.keys, table.find(playerindex.keys, key))
end
end
end)
HOST_TIMESCALE = 1.0
SV_WALKSPEED = 100
local function movementLoop(p)
while wait((HOST_TIMESCALE * 50) / 1000) do
if not p.base or not game.Players:FindFirstChild(p.base.Name) then
break
end
if not p.base.Character then
continue
end
local velset: LinearVelocity = p.base.Character:WaitForChild("vel")
p.wishmove = processKeys(p.keys)
if p.wishmove ~= vector3.zero then
if p.wishmove.Y == 1 then
--TODO: implement jump
end
p.vel.X = p.wishmove.X * SV_WALKSPEED
p.vel.Z = p.wishmove.Z * SV_WALKSPEED
end
velset.VectorVelocity = p.vel:back() --ok
end
end
game.Players.PlayerAdded:Connect(function(play)
local p = player
p.base = play
table.insert(PLAYERS, {play.Name, p})
play.Destroying:Connect(function()
local _, numb = findp(player.Name)
table.remove(PLAYERS, numb)
end)
play.CharacterAdded:Connect(function(char)
char:WaitForChild("Humanoid").EvaluateStateMachine = false
char:WaitForChild("Humanoid").AutoRotate = false
local li = Instance.new("LinearVelocity")
li.Name = "vel"
li.Parent = char
li.Attachment0 = char:WaitForChild("HumanoidRootPart"):WaitForChild("RootAttachment")
end)
spawn(function()
movementLoop(p)
end)
end)