How to make character walk on a slope correctly?
Asked by
7 years ago Edited 7 years ago
I need help with making this script affect the torso of the character, instead of a random part.
What I'm trying to do, is this https://twitter.com/egomoose/status/740277001244774400
This script below does the same, but to a part created by an instance. Help?
Trying to make this script do the same thing as...
01 | local mouse = game.Players.LocalPlayer:GetMouse() |
02 | local moveModel = game.Players.LocalPlayer.Character; |
04 | mouse.TargetFilter = moveModel |
08 | local hrp = c:WaitForChild( "HumanoidRootPart" ) |
09 | local j = hrp:WaitForChild( "Root Hip" ) |
12 | function placeAtMouse() |
17 | local point = moveModel.Torso.Position; |
20 | moveModel.Torso.Position, |
21 | Vector 3. new( 0 , - 10 , 0 ) |
23 | local hit, pos, normal = workspace:FindPartOnRay(ray, moveModel) |
25 | local origin = point + Vector 3. new( 0 , 0.1 , 0 ) |
28 | local ray = Ray.new(origin, Vector 3. new( 0 , - 1 , 0 )) |
31 | local cross = Vector 3. new( 0 , 1 , 0 ):Cross(normal) |
32 | local angle = math.asin(cross.magnitude) |
34 | local savedCFrame = moveModel.Torso.Orientation; |
37 | j.C 0 = orig*CFrame.fromAxisAngle(cross.magnitude = = 0 and Vector 3. new( 1 ) or cross, angle) |
39 | brick.CFrame = part.CFrame |
This script down here!!!
01 | local player = game:GetService( "Players" ).LocalPlayer; |
02 | local character = player.CharacterAdded:wait(); |
04 | local torso = character:WaitForChild( "HumanoidRootPart" ); |
06 | function drawray(ray, parent) |
07 | local part = Instance.new( "Part" , parent or game.Workspace.CurrentCamera); |
08 | part.FormFactor = Enum.FormFactor.Custom; |
09 | part.Material = Enum.Material.Neon; |
10 | part.Size = Vector 3. new(. 2 , ray.Direction.magnitude, . 2 ); |
11 | part.CFrame = CFrame.new(ray.Origin + ray.Direction/ 2 , ray.Origin + ray.Direction) * CFrame.Angles(math.pi/ 2 , 0 , 0 ); |
13 | part.CanCollide = false ; |
14 | part.BrickColor = BrickColor.new( "Bright red" ); |
19 | local part = Instance.new( "Part" ); |
21 | part.CanCollide = false ; |
22 | part.FormFactor = Enum.FormFactor.Custom; |
23 | part.Material = Enum.Material.Neon; |
24 | part.Size = Vector 3. new( 2 , 1 , 2 ); |
26 | part.TopSurface = Enum.SurfaceType.Smooth; |
27 | part.BottomSurface = Enum.SurfaceType.Smooth; |
29 | part.BrickColor = BrickColor.Green(); |
32 | local ray = Ray.new(torso.Position, Vector 3. new( 0 , - 50 , 0 )); |
33 | local hit, pos, normal = game:GetService( "Workspace" ):FindPartOnRayWithIgnoreList(ray, { character } ); |
34 | local cross = normal:Cross(Vector 3. new( 0 , 1 , 0 )); |
35 | local angle = math.asin(cross.magnitude); |
37 | local lateral = torso.CFrame - torso.CFrame.p; |
41 | new.Parent = character |
42 | new.CFrame = CFrame.new(pos) * CFrame.fromAxisAngle(cross = = Vector 3. new() and Vector 3. new( 1 ) or cross, -angle) * lateral; |
49 | game:GetService( "RunService" ).RenderStepped:connect( function () |