#Find if player is on slope

56 messages · Page 1 of 1 (latest)

open slate
#

Hi!

How could I go about finding out if a player is on a slope/non flat ground?

shy slate
#

you could raycast from your character to below the character and then check its normal by the RaycastResult.Normal

shy slate
#

the normal gives you a vector which says which direction the slope is facing

#

then you can just check its y component and done

shy slate
open slate
#

local rayResult = workspace:Raycast(humanoidRootPart.Position,humanoidRootPart.Position - Vector3.new(0,10,0) - humanoidRootPart.Position,params)

shy slate
#

raycasting works for terrain as well i think so

open slate
#

wdym why

shy slate
#

why -

#

why "-" i mean

open slate
#

To draw it from the player's position

shy slate
#

ah ok

#

but

open slate
#

humanoidRootPart.Position - Vector3.new(0,10,0) - humanoidRootPart.Position is the only time ive ever gotten a raycast to cast below a player which is weird

shy slate
#

you can just do humanoidRootPart.Position - Vector3.new(0, 2000, 0)

open slate
#

How come that works?

shy slate
#

your code subtracts your players position, then subracts it by 10, and then subtracts it again by your players position

#

you can just subtract it by a big arbitrary value like 2000

open slate
shy slate
#

so that we get a ray pointing downwards towards 2000

#

ah you want the slope if the player is touching it right?

open slate
#

yes

shy slate
#

the do a small value like

#

0.5 or 1

open slate
#

and how would i cast it at their feet since it casts at their torso right now

shy slate
#

in the RaycastParams add the whole character to the FilterInstanceDecendants

#

aka { character }

open slate
#

added that

shy slate
#

try

open slate
#

params.FilterDescendantsInstances = {player.Character}

params.FilterType = Enum.RaycastFilterType.Blacklist```
shy slate
#

the filter type is by default blacklist so you dont have to add that

open slate
#

oh cool lemme delete thst line

#

how far down would I want to raycast for jusut below the feet or should i just do trial and error til i get it

shy slate
#

oh wait i realised youre casting from your rootpart

#

just get the character's bounding box by :GetBoundingBox() and then half it (/2) and then subtract it from the rootpart, and then subtract it by 0.5 or 1

open slate
#

lemme give that a try

#

local rayResult = workspace:Raycast(humanoidRootPart.Position,player.Character:GetBoundingBox().Position / 2 - Vector3.new(0,1,0),params)

shy slate
#

bounding box is a position so you can remove the .Position

open slate
shy slate
#

ohhh wait i just realized

#

dont divide it by 2

#

also dont remove .Position then

#

wait

#

instead of get bounding box

#

use :GetExtentsSize()

open slate
#

Instead of boundingbox?

shy slate
#

yes

open slate
#

the while wait() is temporary

#

im just trying to get this detection working before i use it anywhere

shy slate
#

workspace:Raycast(origin, direction)

#

origin is the place of origin

#

direction is which way it should be facing

#

so our origin is the rootpart's position