- What do you want to achieve? Keep it simple and clear!
I’m trying to learn ways/methods to how I can make a player swap surfaces of a part in my wall climbing system.
- What is the issue?
I’m having issues thinking of ways I can make my wall climbing system swap sides.
Whole Client
local CollectionService = game:GetService("CollectionService")
local PlayerService = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Debris = game:GetService("Debris")
local Player = PlayerService.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character.PrimaryPart
local Humanoid = Character:WaitForChild("Humanoid")
local wallClimb = false
local waitGyro = nil
local waitPos = nil
local connection1
local connection2
local cd = 0.25
local function Choice(...)
local args = {...}
Humanoid.PlatformStand = args[4]
Humanoid.AutoRotate = args[1]
Humanoid.WalkSpeed = args[2]
Humanoid.JumpPower = args[3]
end
local function Raycast(...)
local args = {...}
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {Character}
local origin = args[2]
local direction = args[3]
local result = workspace:Raycast(origin,direction,params)
if args[1] == "Attach" then
if result and result.Instance == args[4] then
return CFrame.lookAt(result.Position,result.Position + -result.Normal)
end
elseif args[1] == "Swap" then
if result == nil then
return "Returned"
end
end
end
local function bodyGyro()
local gyro = Instance.new("BodyGyro")
gyro.MaxTorque = Vector3.new(1e6,1e6,1e6)
gyro.Parent = HumanoidRootPart
return gyro
end
local function bodyPosition()
local pos = Instance.new("BodyPosition")
pos.MaxForce = Vector3.new(1e6,1e6,1e6)
pos.Parent = HumanoidRootPart
return pos
end
local function Move()
local keyDownTable = {
UserInputService:IsKeyDown(Enum.KeyCode.W),
UserInputService:IsKeyDown(Enum.KeyCode.A),
UserInputService:IsKeyDown(Enum.KeyCode.S),
UserInputService:IsKeyDown(Enum.KeyCode.D)
}
if keyDownTable[1] then
waitPos.Position = waitPos.Position + Vector3.new(0,0.25,0)
end
if keyDownTable[2] then
waitPos.Position = waitPos.Position + Vector3.new(0.25,0,0)
end
if keyDownTable[3] then
waitPos.Position = waitPos.Position + Vector3.new(0,-0.25,0)
end
if keyDownTable[4] then
waitPos.Position = waitPos.Position + Vector3.new(-0.25,0,0)
end
end
local function Clean()
if wallClimb == true then
coroutine.wrap(function()
Debris:AddItem(waitPos,cd)
Debris:AddItem(waitGyro,cd)
task.wait(cd)
waitPos = nil
waitGyro = nil
connection1:Disconnect()
connection2:Disconnect()
Choice(true,16,50,false)
wallClimb = false
end)()
end
end
local function ifNil()
local nilRaycast = Raycast("Swap",HumanoidRootPart.Position,HumanoidRootPart.CFrame.LookVector * 4,nil)
if nilRaycast == "Returned" then
Clean()
end
end
for _,Wall in ipairs(CollectionService:GetTagged("Wall")) do
Wall.Touched:Connect(function()
if not wallClimb then
local attachResult = Raycast("Attach",HumanoidRootPart.Position,HumanoidRootPart.CFrame.LookVector * 4, Wall)
if attachResult ~= nil then
wallClimb = true
Choice(false,0,0,true)
local gyro = bodyGyro()
local pos = bodyPosition()
waitGyro = gyro
waitPos = pos
HumanoidRootPart.CFrame = attachResult
waitGyro.CFrame = HumanoidRootPart.CFrame
waitPos.Position = HumanoidRootPart.Position
connection1 = RunService.Heartbeat:Connect(Move)
connection2 = RunService.Heartbeat:Connect(ifNil)
end
end
end)
end
- What solutions have you tried so far?
I’ve thought of rotating 90 degrees using my gyro based on which key I was holding but I remember the last time I attempted to make a wall climbing system that only ruined my code.
Test: Home - Roblox
There are bugs but I am looking for ideas on how to swap sides.
Thanks, have a nice day!