Player falls in my climbing script (help pls)

Hi I am trying to script climbing in my game

I currently have the bare minimum. I’ll add the align orientation stuff later (do i just tween player to face wall??)


local function heartBeatService(_deltaTime)
	if canClimb ==  true then
		local keyPressed = game.UserInputService:GetKeysPressed()
		contains(keyPressed, Enum.KeyCode.W)
		if contains(keyPressed, Enum.KeyCode.W) == true then
			hrp.AssemblyLinearVelocity += Vector3.new(1, 4, 1)
			local rayOrigin = Character.HumanoidRootPart.position
			local rayDirection = Character.HumanoidRootPart.CFrame.LookVector
			local raycastResult = workspace:Raycast(rayOrigin, rayDirection*10)
			if raycastResult == nil then
				canClimb = false
--check if facing wall
			end
		end
	end
end

--[[local function climbState(canClimb)
	if canClimb == true then
	end
end
]]
local function climb(actionName, InputState)
--test raycast if it can see wall if it can turn the wall red
	if actionName == "climb" and InputState == Enum.UserInputState.Begin then
		--idiot had action name true
			print("climb script initiated")
--set inputstate to begin
			local rayOrigin = Character.HumanoidRootPart.position
			--why cant i use my variable why do i have to use "HumanoidRootPart", maybe be cause its inbetween???
			local rayDirection = Character.HumanoidRootPart.CFrame.LookVector
--set filter 
--if angle and distance is within set value >> then >> can climb = true
			local raycastResult = workspace:Raycast(rayOrigin, rayDirection*10)
-- set distance to shorter
--climbing heartbeat(outside)
			if raycastResult then
				local lookVector = Character.HumanoidRootPart.CFrame.LookVector
				local normal = raycastResult.Normal
				local climbAngle = lookVector:Dot(normal)
				print(climbAngle .. "pens")
				if climbAngle <= -0.8 then
					humanoid:ChangeState(Enum.HumanoidStateType.PlatformStanding)
					canClimb = true
					print(climbAngle .. "in range of my cum shot")
					-- set body gyro and shit
					-----------climbState(canClimb)
					--  will it still run heartbeat service if i dont runService.Heartbeat:Connect(heartbeatClimb)
				return
			end
				end
			end
-- if raycastresult = instance else end
--check distance
--check angle
--set angle
--set distance
--move up and down while or if in climbstate
-- study look vectors
	end 

using the method i use the climb the wall the player velocity is like getting multiplied (not really an issue i can fix)

velocity = 0 0 0
if W then velocity add 0 1 0
if A then velocity add 0 0 1
if S then velocity add 0 -1 0
if D then velocity add 0 0 -1
player.velocity = velocity

this is the solution i have if that make sense

do i turn player gravity of so it dosent fall or do i have to change the humanoid state is what i need help with, because player falls of the all when he climbs ty in advance

2 Likes

You should anchor the player and CFrame them, instead of velocity

1 Like

ur so smart holy let me try dat and clap yo ****. TY OMG

1 Like

I set the player to anchored he can no longer move

i tried to anchor him with align position but only aligns for a split second then disconnects

any other ideas?

1 Like

you can try the formula

TotalMass*gravity + desired velocity

to get the total mass, loop through the character model and change a variable by the part’s :GetMass()

it should look like this

local mass = 0
for i , e in pairs(char:GetDecendence())
if e:IsA("BasePart") than
mass += e:GetMass
end
end

do not directly copy this script as im on mobile and not in studio at the time of writing