Hello. I am currently making a game with features which allows users to pass through certain walls. However, I do not want the players to be able to see ahead of them while passing through. So currently I have a raycast to look forward. If the player is within a part, the raycast will collide very close.
However, it seems the raycast only collides with the side of these walls, and if a player is within a wall, it only hits again after exiting it. How do I go about this then?(Players are always in first person)
Update: After one more test, I’ve concluded that the ray doesn’t hit either when exiting the wall.
I did read your message, and I’m trying to help. I don’t know what to do in that case besides making a script to change it. Try not to be rude when someone is attempting to help you.
I’m sorry it’s just infuriating when someone asks me if I have my wall’s collision off correctly when I clearly state in the message that the ray is not hitting while my head is inside the wall. And, oh wow, make a script to change it, who would’ve thought?
Of course it’s obvious! But why would I need to ask for help just for someone to tell me to “change the script”? I’m not trying to be rude to those trying to assist me, but like, no offence, but you’re not really helping…
Okay then, I’ll stop trying to help you. You can’t expect me to go and think of a script right now that will fix the problem. Just experiment with it to see what works.
I don’t expect you to give me a script. I was asking a question to see if someone knew how to detect a part while inside of it by using rays or some other method. But you just rushed in with an answer saying “change the FOV when exiting the part”. I appreciate your attempt to help, but really, I think I’ll ask someone else.
Thanks for the reply. Unfortunately, region3 is not possible as parts will have to each be individually identified and scripted, and because there are diagonal parts and meshes. It would be preferable to stick to the old method. Do you know if there’s a way to make these parts not fail when inside a part?
I don’t have the best knowledge about RayCasting so someone who knows better could help but if your attempting to fire a ray from inside another part pretty sure it will just ignore it. I’ll do some testing of my own and tell you the results.
You could try raycasting across a players head (x axis) or from back to front of the players head (z axis), by getting an vector from the left and right side of the players head, respectively. Using these two vectors, you can construct a unit vector that runs across them. I haven’t tested, but I do find recommend using other alternatives such as the above, because raycasting is not really needed here.
local runService = game:GetService('RunService')
local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild('Head')
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {character}
raycastParams.IgnoreWater = true
runService.RenderStepped:Connect(function()
local origin = (head.CFrame * CFrame.new(head.Size.X/2,0,0)).Position
local endOrigin = (head.CFrame * CFrame.new(-head.Size.X/2,0,0)).Position
local direction = (origin-endOrigin).Unit * -head.Size.X
local ray = workspace:Raycast(origin, direction, raycastParams)
if ray then
print("Object/terrain hit:", ray.Instance:GetFullName())
end
end)