ColdFoxy07
(ColdFoxy)
November 29, 2023, 4:16pm
#1
Hey there! I’m trying to cast a raycast to the right side of the humanoid, but it’s always returning nil, what is going on?
Script (local, StarterCharacterScripts):
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {character}
local maxDistance = 2.5
repeat
runService.RenderStepped:Wait()
local rayR2 = workspace:Raycast(humanoid.RootPart.Position, humanoid.RootPart.CFrame.RightVector * maxDistance, rayParams)
print(rayR2)
until not rayR2
Any help is appreciated!
1 Like
You probably need to define rayR2 out of the repeat function, then reset it using “rayR2 =”
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {character}
local maxDistance = 2.5
local rayR2
repeat
runService.RenderStepped:Wait()
rayR2 = workspace:Raycast(humanoid.RootPart.Position, humanoid.RootPart.CFrame.RightVector * maxDistance, rayParams)
print(rayR2)
until not rayR2
1 Like
ColdFoxy07
(ColdFoxy)
November 29, 2023, 4:20pm
#3
It still returns nil, but it does seem to work when I do it on the left side:
repeat
runService.RenderStepped:Wait()
local rayL2 = workspace:Raycast(humanoid.RootPart.Position, humanoid.RootPart.CFrame.RightVector * -maxDistance, rayParams)
print(rayL2)
until not rayL2
(all the variables stay the same)
1 Like
Can you print the ray direction on the r2?
1 Like
2.5 studs is suppppper short. Basically, if something isn’t touching this blue line you’re going to get nil.
1 Like
ColdFoxy07
(ColdFoxy)
November 29, 2023, 4:52pm
#7
Yes, I know that. It’s supposed to be short since it is used for a wallrunning script, where the arm will clip into the wall anyways. It does seem to be working when I do it on the left side, just not the right side for whatever reason.
1 Like
So if you increase it to 5 is it still nill.
2 Likes
Dlbsp1983
(DLB)
November 29, 2023, 4:54pm
#10
And humanoid.rootpart isn’t character.HumanoidRootPart.
Sorry never got to it this way
2 Likes
ColdFoxy07
(ColdFoxy)
November 29, 2023, 4:55pm
#11
It works everywhere else, so it should work here too.
1 Like
Can you send an image or video? You’re starting with something on your side that should instantly trigger it?
2 Likes
Dlbsp1983
(DLB)
November 29, 2023, 4:56pm
#13
Oh ok what if you just print.
humanoid.RootPart.CFrame.RightVector
2 Likes
ColdFoxy07
(ColdFoxy)
November 29, 2023, 4:57pm
#14
Then it will print out 0, 0, -1
1 Like
ColdFoxy07
(ColdFoxy)
November 29, 2023, 4:58pm
#15
Yes, there is a wall on my side.
1 Like
Dlbsp1983
(DLB)
November 29, 2023, 4:59pm
#16
Yes sorry just trying to figure why would the left work.
2 Likes
ColdFoxy07
(ColdFoxy)
November 29, 2023, 5:01pm
#17
Oh my god I feel so stupid, I just realized it was because of the way I turn my character to be adjacent with the wall, and that being the wrong way. Sorry everyone!
3 Likes
system
(system)
Closed
December 13, 2023, 5:02pm
#18
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.