#Weird wall detection behavior in my game

1 messages · Page 1 of 1 (latest)

bright ore
#

hey yall. currently trying to figure out how to implement good wall detection for wall sliding/wall jumping in my game. i have code implemented but for some reason i can't get the character to just look at the surface of the wall...any idea what im doing wrong? attached is the video of what happens and the code that runs every frame.

local function updateWallDetection()
    if controllerManager.ActiveController == airController then
        local cameraLookVector = cameraLookVectorNoY()

        local wallFindCast = workspace:Blockcast(rootPart.CFrame, characterSize, cameraLookVector * (characterSize.Z/2 + 0.1), raycastParams)

        if wallFindCast then
            disableMultipleInputContexts({airContext, climbContext})
            enableInputContext(wallContext)

            local wallNormal = wallFindCast.Normal
            local finalWallCast = workspace:Blockcast(rootPart.CFrame, characterSize, -wallNormal * (characterSize.Z/2 + 0.1), raycastParams)

            if finalWallCast then
                isHuggingWall = true

                moveAction:GetBinding("WASDBinding"):SetDirections({
                    Up = Enum.KeyCode.Unknown,
                    Down = Enum.KeyCode.Unknown
                })

                wallCastPart.Position = finalWallCast.Position

                local lookPosition = finalWallCast.Position
                local futureCFrame = CFrame.new(rootPart.Position, lookPosition)
                character:PivotTo(futureCFrame)

                print("[CharacterServiceClient] Wall detected.")
            end
        else
            moveAction:GetBinding("WASDBinding"):SetDirections({
                Up = Enum.KeyCode.W,
                Down = Enum.KeyCode.S
            })

            disableInputContext(wallContext)
            isHuggingWall = false
        end
    end
end
silent crescent
#
if finalWallCast then
    isHuggingWall = true

    moveAction:GetBinding("WASDBinding"):SetDirections({
        Up = Enum.KeyCode.Unknown,
        Down = Enum.KeyCode.Unknown
    })

    wallCastPart.Position = finalWallCast.Position
    local wallNormal = wallFindCast.Normal

    local flatNormal = Vector3.new(wallNormal.X, 0, wallNormal.Z).Unit

    local lookPosition = rootPart.Position - flatNormal

    local futureCFrame = CFrame.lookAt(rootPart.Position, lookPosition)
    character:PivotTo(futureCFrame)

    print("[CharacterServiceClient] Wall detected.")
end

try this

eternal plankBOT
#
Luau Compiler Results | Server #58

Requested by: @silent crescent```ansi
No Output

bright ore
#

did you try to run it 😭

#

anyways i'll try it

silent crescent
#

but that should fix that glitch

#

lmk if not

bright ore
#

okay so it fixed the issue of the character look everywhere but the wall

#

it looks directly at the surface of the wall but there's another issue where it keep going down to the ground every time the function's called

#

im assuming its cause i don't have other behavior setup to handle that yet, but just in case i'll send a vid here of what i mean

silent crescent
#

ohh

eternal plankBOT
#
Luau Compiler Results | Server #60

Requested by: @silent crescent```ansi
Detected code block in command ['lua {CODE} ']. Remove code block or use an application command instead.
1: Expected identifier when parsing expression, got ``

#
Luau Compiler Results | Server #60

Requested by: @silent crescent```ansi
1: Expected <eof>, got 'end'

silent crescent
#

wait try this ```lua
if finalWallCast then
isHuggingWall = true

moveAction:GetBinding("WASDBinding"):SetDirections({
    Up = Enum.KeyCode.Unknown,
    Down = Enum.KeyCode.Unknown
})

local wallNormal = finalWallCast.Normal
local flatNormal = Vector3.new(wallNormal.X, 0, wallNormal.Z)

if flatNormal.Magnitude > 0 then
    flatNormal = flatNormal.Unit
    
    local wallTouchPoint = finalWallCast.Position
    local desiredPosition = wallTouchPoint + (flatNormal * (characterSize.Z / 2))
    local finalPos = Vector3.new(desiredPosition.X, rootPart.Position.Y, desiredPosition.Z)
    local lookPosition = finalPos - flatNormal
    
    character:PivotTo(CFrame.lookAt(finalPos, lookPosition))
end

rootPart.AssemblyLinearVelocity = Vector3.new(0, 0, 0) 

print("[CharacterServiceClient] Wall hugging active.")

end

bright ore
#

better! it looks like its actually starting to do a wall slide now

#

however the character jitters left and right while sliding, gonna record another vid

#

wtf

#

dude why are you on marketplace blacklist?

silent crescent
#

i dont remember it was a year ago

silent crescent
# bright ore

also is the issue solved or would you still like help with this

bright ore
#

how do i stop the camera and/or character (idk which it is) from doing this weird vibration while wall sliding?

silent crescent
#

Seems like an optimisation issue

#

probably use prediction and cache all of the movements that way it will move smoothly towards to the target