Hello! I’m making my own custom character controller for a climbing system I’m making. I’m having a problem at changing the position of player. I’m adding a number to x position of player but it dont seem to work too well like uh it works if I climb the front face of the wall but if I climb the back face of the wall the A and D controls invert for some reason.
My code to change the position:
local Character = player.Character
local humanoid = Character.Humanoid;
local rootPart = Character.Humanoid.RootPart;
local X = 0;
if Param1 == "A" then
X = 0.5
elseif Param1 == "D" then
X = -0.5
end
rootPart.Anchored = true
local CF = Character.PrimaryPart.CFrame + Vector3.new(X,0,0)
Character:SetPrimaryPartCFrame(CF)
Thats done in server. Because when I did that in client the position dont replicated.
Well, you cant really notice the controls that are inverting but here:
I have a get touching parts system to verify if player is still climbing or not, but that dont works when I’m climbing the back face of a wall because the controls invert.
That shouldn’t happen to the player’s default Character, position replicates.
Also, it’s not 'inverting, it’s moving in the x direction you’re making it move. You can compare the player’s Z position to the wall’s to determine if they’re in the front or back.If they’re in the back, just switch the direction they’re moving in.
I don’t know if player Z > wall Z is front or back, but this is how it would look:
local Character = player.Character
local humanoid = Character.Humanoid;
local rootPart = Character.Humanoid.RootPart;
local X = 0;
local dirX = 1
if Character.PrimaryPart.Position.z < Wall.Position.z then -- I don't know what you called your wall.
dirX = -1
end
if Param1 == "A" then
X = 0.5*dirX
elseif Param1 == "D" then
X = -0.5*dirX
end
rootPart.Anchored = true
local CF = Character.PrimaryPart.CFrame + Vector3.new(X,0,0)
Character:SetPrimaryPartCFrame(CF)
if this reverses it, then change “<” to “>”.
Also as for not replicating, the issue might be if you manually change the character (like player.character = model). If you didn’t, it should replicate. But a way to ensure it replicates is
to setnetworkowner of root part. (But this shouldn’t have to be done, networkownership of player’s character is player by default unless you manually change the character)
for sides, you need to do more stuff. Start of by checking if Player is in the front or back on your previous code.
local Character = player.Character
local humanoid = Character.Humanoid;
local rootPart = Character.Humanoid.RootPart;
if Character.Position.x > Wall.Position.x - Wall.Size.x/2 and Character.Position.x < Wall.Position.x + Wall.Size.x/2 -- Checks if player is not on sides.
local X = 0;
local dirX = 1
if Character.PrimaryPart.Position.z < Wall.Position.z then -- I don't know what you called your wall.
dirX = -1
end
if Param1 == "A" then
X = 0.5*dirX
elseif Param1 == "D" then
X = -0.5*dirX
end
rootPart.Anchored = true
local CF = Character.PrimaryPart.CFrame + Vector3.new(X,0,0)
Character:SetPrimaryPartCFrame(CF)
else -- Player is on the sides
-- here, you have to do what you did except this time you're working with z instead of x. try it yourself first, and I can help if you can't do it.
end
local Character = player.Character
local humanoid = Character.Humanoid;
local rootPart = Character.Humanoid.RootPart;
local Wall = Param2
if Character.PrimaryPart.Position.X > Wall.Position.X - Wall.Size.X and Character.PrimaryPart.Position.X < Wall.Position.X + Wall.Size.X then -- Checks if player is not on sides.
local X = 0;
local dirX = 1
if Character.PrimaryPart.Position.X < Wall.Position.X then -- I don't know what you called your wall.
dirX = -1
end
if Param1 == "A" then
X = 0.5*dirX
elseif Param1 == "D" then
X = -0.5*dirX
end
rootPart.Anchored = true
local CF = Character.PrimaryPart.CFrame + Vector3.new(X,0,0)
Character:SetPrimaryPartCFrame(CF)
else -- Player is on the sides
-- here, you have to do what you did except this time you're working with z instead of x. try it yourself first, and I can help if you can't do it.
if Character.PrimaryPart.Position.z > Wall.Position.Z - Wall.Size.Z and Character.PrimaryPart.Position.Z < Wall.Position.Z + Wall.Size.Z then -- Checks if player is not on sides.
local X = 0;
local dirX = 1
if Character.PrimaryPart.Position.Z < Wall.Position.Z then -- I don't know what you called your wall.
dirX = -1
end
if Param1 == "A" then
X = 0.5*dirX
elseif Param1 == "D" then
X = -0.5*dirX
end
rootPart.Anchored = true
local CF = Character.PrimaryPart.CFrame + Vector3.new(X,0,0)
Character:SetPrimaryPartCFrame(CF)
end
end
haven’t tested this, but here you should be comparing x and changing z.
local Character = player.Character
local humanoid = Character.Humanoid;
local rootPart = Character.Humanoid.RootPart;
if Character.Position.x > Wall.Position.x - Wall.Size.x/2 and Character.Position.x < Wall.Position.x + Wall.Size.x/2 -- Checks if player is not on sides.
-- ... Same as before
else -- Player is on the sides
local Z = 0;
local dirZ = 1
if Character.PrimaryPart.Position.x < Wall.Position.x then -- I don't know what you called your wall.
dirZ = -1
end
if Param1 == "A" then
Z = 0.5*dirZ
elseif Param1 == "D" then
Z = -0.5*dirZ
end
rootPart.Anchored = true
local CF = Character.PrimaryPart.CFrame + Vector3.new(0,0,Z)
Character:SetPrimaryPartCFrame(CF)
end
local Character = player.Character
local humanoid = Character.Humanoid;
local rootPart = Character.Humanoid.RootPart;
local PrimaryPart = Character.PrimaryPart
local Wall = Param2
if PrimaryPart.Position.X > Wall.Position.X - Wall.Size.X and PrimaryPart.Position.X < Wall.Position.X + Wall.Size.X then -- Checks if player is not on sides.
local X = 0;
local dirX = 1
if PrimaryPart.Position.X > Wall.Position.X then -- I don't know what you called your wall.
dirX = -1
end
if Param1 == "A" then
X = 0.5*dirX
elseif Param1 == "D" then
X = -0.5*dirX
end
rootPart.Anchored = true
local CF = PrimaryPart.CFrame + Vector3.new(X,0,0)
Character:SetPrimaryPartCFrame(CF)
else -- Player is on the sides
-- here, you have to do what you did except this time you're working with z instead of x. try it yourself first, and I can help if you can't do it.
local Z = 0;
local dirZ = 1
if PrimaryPart.Position.X > Wall.Position.X then -- I don't know what you called your wall.
dirZ = -1
end
if Param1 == "A" then
Z = 0.5*dirZ
elseif Param1 == "D" then
Z = -0.5*dirZ
end
rootPart.Anchored = true
local CF = PrimaryPart.CFrame + Vector3.new(0,0,Z)
Character:SetPrimaryPartCFrame(CF)
end