local Monster = script.Parent
local Core = Monster.Core
local TargetPoint = Monster.TargetPoint
local Target = Monster.Target
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Monster}
while wait() do
local LookVector = Core.CFrame.LookVector + Vector3.new(0,-0.2,0)
local RayOrigin = Core.Position
local RayDirection = LookVector * 100
local RaycastResult = workspace:Raycast(RayOrigin, RayDirection, raycastParams)
if RaycastResult then
TargetPoint.Position = RaycastResult.Position + Vector3.new(0,0.5,0)
if (Target.Position - TargetPoint.Position).Magnitude >= 14 then
Target.Position = TargetPoint.Position
end
end
end
Here’s what my explorer looks like:
Ive changed local LookVector = Core.CFrame.LookVector + Vector3.new(0,-0.2,0) to local LookVector = Core.CFrame.LookVector + Vector3.new(0,-0.2,-0.2), and it works like the picture I provide, but once the monster turns, the offset isnt the right way since I dont think its relative. Can someone help me so that it looks like the 2nd picture no matter which way the monster is facing? Thank you in advance!
The LookVector is a directional vector of the forward face in global space, I mean it would be pretty useless to have a property of an object that was just always (0, 0, -1).
If we set the LookVector as the origin (0,0,0) then (0,-.2,-.2) is where we’re we will be aiming for. Now it’s as simple as coverting that vector to the world space so it is no longer relative to the LookVector and is the direction we want it to go in the world.
VectorToWorldSpace is not a valid member of Vector3
I dont mean to just return an error and make you do the work, I tried looking at the documentation, VectorToWorldSpace is for CFrame but Im kind of lost and don’t know how to fix this. I kind of just guessed and put CFrame instead of Vector3 but nothing happens. Is there any other explanation or help you can provide?
As I understand you want the ray to shoot in the direction of the npc but with an offset down and to the left
To do that you can define the X, Y and Z components of the vector and then make them relative to the npc’s rotation
First you need to define the X component which is how much the vector is offset in the right direction,
now you need the offset to be the opposite of right which is left so you add a - sign
Then you need to define the Y component which is how much the vector is offset in the up direction,
you need the offset to be the opposite of up which is down so again you add a - sign
And finally, you need to define the Z component which is how much the vector is offset in the backward direction, you can make the ray shoot in the direction of the npc by adding a front offset to the vector
you need the offset to be the opposite of back which is front so yet again you add a - sign
And then you just need to make the vector relative to the npc’s rotation so you can use the VectorToWorldSpace function of CFrame which makes the vector relative to the rotation of the CFrame
The final code should look like this
local LookVector = Core.CFrame:VectorToWorldSpace(Vector3.new(-0.2, -0.2, -1))