Hello I am trying to do a raycast to see if a monster can see a player or if something is in the way.
here is my code
local rayOrigin = monsterHumanoidRootPart.Position
local rayDirection = Vector3.new(0, -100, 0) -- code here to put direction of player
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
how do I make a racyast to see if a monster can see the player? I think all I have to do is put the correct direction but I dont know how to get the direction;
If you meant as in the direction of their characters. Use HumanoidRootPart.CFrame.LookVector which gives about exactly one stud away frontally.
If you meant as in the direction of their camera, it requires a little more effort by getting the player to send the CFrame of it and the same thing as above. If it is tied to a first-person camera, use the Head.CFrame.LookVector.
After you get this one LookVector, multiply it by a number for its length.
So if you have a monster and you want to raycast between it and the player. I’d assume you want (Monster.Head - PlayerCharacter.Head).Magnitude or something along those lines. Or was it Vector3.Unit?
Hello I am trying to fire a raycast from the monster humanoidrootpart and toward the player’s humanoidrootpart. I then want to see if something is in the way.
Here is my code so far:
local rayOrigin = plr.Character.HumanoidRootPart.Position
local rayDirection = plr.Character.HumanoidRootPart.CFrame.LookVector
local raycastRelsult = workspace:Raycast(rayOrigin, rayDirection)
something I think I need to do is add params and then add the parts of the monster to the blacklist so that it doesnt count the monster as a part that gets hit however I forgot how to do this
it would be more complicated to have to manage a hitbox for detecting when a wall is in the way as I would have to manage the hitbox as well as the raycast