Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make player rotate to the slope they are walking on?

To explain what I'm trying to do;

A humanoid for example walks up a ramp. The humanoid acts as if hes still walking on flat ground trying to walk through the ramp instead of walking up the ramp.

I want to prevent this.

local mouse = game.Players.LocalPlayer:GetMouse()
local moveModel = game.Players.LocalPlayer.Character;
-- don't detect the model we're moving
mouse.TargetFilter = moveModel


local c = moveModel;
local hrp = c:WaitForChild("HumanoidRootPart")
local j = hrp:WaitForChild("Root Hip")
local orig = j.C0
 
function placeAtMouse()
	-- make sure the mouse is pointing at something
	if mouse.Target then
		-- where we cast our ray from (shifted slightly up so the ray will hit the surface we're hovering)
	
	local point = moveModel.Torso.Position;
	
	local ray = Ray.new(
                moveModel.Torso.Position,
                Vector3.new(0, -10, 0)
            )
local hit, pos, normal = workspace:FindPartOnRay(ray, moveModel)
	if hit ~= nil then
		local origin = point + Vector3.new(0, 0.1, 0)
 	
		-- cast our ray and get our normal, which is a unit vector
		local ray = Ray.new(origin, Vector3.new(0, -1, 0))
 
		-- get the perpendicular vector and the angle between the two
		local cross = Vector3.new(0, 1, 0):Cross(normal)
		local angle = math.asin(cross.magnitude) -- division by 1 is redundant
		local dude = script:WaitForChild("AngleValue")
		dude.Value = angle
 	print(angle)
local savedCFrame = moveModel.Torso.Orientation;




j.C0 = orig*CFrame.fromAxisAngle(cross.magnitude == 0 and Vector3.new(1) or cross.unit, angle)


		--moveModel.Torso.CFrame = 
			--(CFrame.new(moveModel.Torso.Position)) -- position
			--* CFrame.fromAxisAngle(cross.magnitude == 0 and Vector3.new(1) or cross.unit, angle) -- angle, cross must not be Vector3.new()
		
	
	local newCFrame;
	
	end
	end
end
 
-- check every frame
game:GetService("RunService").RenderStepped:connect(function()
	placeAtMouse()
end)

2 comments

0

well please desscribe you question explain what you want.

0

How maybe could find the part he is walking on by using a ray. Then, match the orientation of the part using a BodyGyro. But this wouldn't work for wedges. Also might prevent you from rotating your player. Sorry if I miss understood your question. Just a thought.

1 answer

OHHHHH DERP. In humanoid properties. Change the max slope angle to what ever you want! (Make it higher)

2 comments

0

omg im sorry i read the comments on community chat you explained. In real life... Yeah idk thats tough mate

0

The maximum slope angle is 89.9. The default is just 89. Won't help.

This discussion is preserved as it was. New answers, comments, and votes are closed.