How would I make someone be able to walk on walls/roofs?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    When a person walks up to a wall, instead of colliding with it, they start to walk on it, as if it was the ground.

  2. What is the issue? Include screenshots / videos if possible!
    I dont know how to do it, lol.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I searched all around the dev forum but no one seems to be talking about this specifically

2 Likes

Here is a basic setup that you could use to achieve this (you are going to have to fill the script in yourself, this is just to get you started).

-- Attach this script to the character

local character = script.Parent

-- Function to check if the character is touching a wall or roof
local function isTouchingWall()
    -- Implement your collision detection logic here
end

-- Function to handle movement
local function move()
    -- Check if the character is touching a wall or roof
    if isTouchingWall() then
        -- Adjust the character's movement to simulate walking on walls or roofs
        -- Apply forces or adjust the character's orientation as needed
    else
        -- Default movement behavior (e.g., walking on the ground)
    end
end

-- Connect the move function to the character's update event
character.Touched:Connect(move)
2 Likes

Okay, i already got that. But how would I achieve actually sticking them to the wall. Sorry I’m just so lost

1 Like

Here is a more updated version with some of the wall logic, but you will still have to fill in certain parts yourself. Hopefully this helps.

-- Attach this script to the character

local character = script.Parent
local stuckToWall = false -- Variable to track whether the character is stuck to a wall

-- Function to check if the character is touching a wall or roof
local function isTouchingWall()
    -- Implement your collision detection logic here
    -- You can use Raycasting or Collision Events to detect if the character is touching a wall
    -- For simplicity, let's assume there's a function called isTouchingWall() that returns true if the character is touching a wall
    return isTouchingWallFunction()
end

-- Function to stick the character to the wall
local function stickToWall()
    -- Apply forces or adjust the character's physics properties to stick to the wall
    -- For simplicity, let's assume you're adjusting the character's orientation to align with the wall
    local wallNormal = -- Calculate the normal vector of the wall the character is touching
    local rotation = CFrame.Angles(math.pi / 2, 0, 0) * CFrame.new(wallNormal)
    character.CFrame = character.CFrame * rotation
    stuckToWall = true
end

-- Function to handle movement
local function move()
    -- Check if the character is touching a wall or roof
    if isTouchingWall() then
        if not stuckToWall then
            -- If not already stuck to a wall, stick to the wall
            stickToWall()
        end
        -- Implement movement logic while stuck to the wall
        -- Apply forces or adjust the character's orientation to simulate walking on walls
    else
        -- Reset the stuckToWall flag if not touching a wall
        stuckToWall = false
        -- Default movement behavior (e.g., walking on the ground)
    end
end

-- Connect the move function to the character's update event
character.Touched:Connect(move)
1 Like

Alright, I’ll see what I can do. Thank you

In the original script, I said to put it as a child of the character, but depending on your use, you may want to update the script so you can put it into StarterPlayerScripts.

There is a gravity controller made by EgoMoose that is is premade and can be used in almost every instance right here. As far as I know the system he has set up is very customizable. If your trying to understand this and make it yourself, I’m clueless. Also, here the link to his game where you can copy the studio:

1 Like

I know I saw that one, wasnt rlly what i was looking for but yea.