Ledge Climbing System (Problems with calculating CFrame when ray hits the wall)

The issue: cm devlog - Roblox Studio (gyazo.com)

The CFrame mostly works for parts that are higher up, I’m guessing this is because it has more time to find the position, but right now I need a way to accurately calculate a ledge each time.

I’ll provided snips of the code if needed.

2 Likes

I think seeing the code would actually alot, just where you oritent the player to the wall would do

Assuming you just need to modify the Y axis to get to the appropriate ledge position, could you just read the hit instance’s position and offset it by its size?

local function getLedgeHeight(raycastPart)
local pos, size = raycastPart.Position, raycastPart.Size

return pos.Y + (size.Y / 2) --//adding additional offset as needed.
end

Yeah, I just thought of that earlier but for some reason now the lookat vector is making me do this
image
This is the line that does all the cframing:

			HumRP.CFrame = CFrame.new(Vector3.new(ray.Position.X,LedgePosition,ray.Position.Z),ray.Position+ray.Normal) * CFrame.Angles(0,math.rad(-180),0)

Hello, I am currently working on my own game and I wanted to implment wall climbing.

I had never made an extensive system but I have finally gotten it to work after hours!

Alright so basically a first I had just made it so that id check if a player was close to either the front, back, left, or right side of the part and then getting the position of the player relative to the position of the part. That worked but when i got to the corners it would snap a way I just didnt like.

Anyways, I just tried raycasting and then getting the relative position of the player to part and it works FLAWLESSLY! Any size part, any rotation it might have!

The blue parts are just visualizer for the relative positioning for the player to the part

Rotated Test

24 x 24 stud test

15 x 15 stud test

First, I raycast 5 studs in front of me

Create the visualizer
image

I use these values to clamp the position so it doesnt go outside of the parts size boundary! And this is also where I get th relative position of the player to the part’s cframe

then I check the normals and then do a bit of math to put the visualizer at the top edge

And now you have the position you can do anything you need to! aka putting the player on the wall

1 Like

Yeah, that works but it only works on parts that have a size with the same 3 values, for the front its fine but for the sides of the disproportional part are inaccurate
cm devlog - Roblox Studio (gyazo.com)

excluding the height, only the z and x values

Hm it seems your goin to have to change some of the math inside of where you assign the positoning, in my game there the same on the x and z so i dont have that problem

so i just tried it now and it seems resizing it only on the x axis will make the front and the back work correctly, but not the left aand right side

OKAY DUDE, i fxied it just now!!!

basically the left and right was using Z size!

updated code

local X = math.clamp(wall.CFrame:ToObjectSpace(root.CFrame).Position.X, -wall.Size.X / 2, wall.Size.X / 2)
local Z = math.clamp(wall.CFrame:ToObjectSpace(root.CFrame).Position.Z, -wall.Size.Z / 2, wall.Size.Z / 2)

if result.Normal == Vector3.new(0,0,1) or result.Normal == Vector3.new(0,0,-1) then
   local pos = wall.Position + result.Normal * wall.Size.Z / 2 + wall.CFrame.UpVector * wall.Size.Y / 2 + wall.CFrame.RightVector * X
   elseif result.Normal == Vector3.new(1,0,0) or result.Normal == Vector3.new(-1,0,0) then
   local pos = wall.Position + result.Normal * wall.Size.X / 2 + wall.CFrame.UpVector * wall.Size.Y / 2 + wall.CFrame.LookVector * -Z
end

ignore the rotation im still working on that lol


yeah thats fixed now…

but the rotation was the issue i also had, i pretty much achieved the same results with the method i used earlier but i guess this is more accurate.

for the angles im trying to use the ray normal and position as the look vector but for some reason its buggy

Uh well what i am doing is just checking the surface normal tthen adjusting the alignorientation attachment cframe by whatever i need it to be

This is for the front and the back

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.