-
What do you want to achieve? My goal is to input the X and Z vectors from the real world into a function, and have the function return the Y position of the vertex or triangle that is at the same or a close X or Z position, or if using RaycastLocal, just the Y position.
-
What is the issue? I’m using RaycastLocal, as the normal Raycast does not work with EditableMesh (due to Beta Features and Hitbox not updating). When I use RaycastLocal, for some reason, it only prints 0,0
and I don’t know what to do with this value. -
What solutions have you tried so far? I have tried to find more information about RaycastLocal because I don’t understand it well, but no one seems to be discussing it at the moment.
My goal is to return a Y value based on how high the MeshPart or vertex is at the position provided (X, Z).
local origin = Vector3.new(-310.75, 6, -132.25)
local direction = Vector3.new(-310.75, -6, -132.25)
local function castRayFromVectors(origin, direction)
if not Variables.EditableMesh then return end
-- Convert the provided world-space origin and direction to object space
local relativeOrigin = Variables.Object.CFrame:PointToObjectSpace(origin)
local relativeDirection = Variables.Object.CFrame:VectorToObjectSpace(direction - origin).Unit
-- Perform the raycast in local space
local triangleId, point, barycentricCoordinate
triangleId, point, barycentricCoordinate = Variables.EditableMesh:RaycastLocal(relativeOrigin, relativeDirection * 100)
if not triangleId then
-- Didn't hit any triangles
print("No Hit Triangles")
return
end
-- Return the coordinates X, Y, Z of the collision point
return point.X, point.Y, point.Z
end
local x, y, z = castRayFromVectors(origin, direction)
if x then
print("Collision X:", x)
print("Collision Y:", y)
print("Collision Z:", z)
-- Visualizer if point
local hitMarker = Instance.new("Part")
hitMarker.Shape = Enum.PartType.Ball
hitMarker.Name = "Marker"
hitMarker.Position = Vector3.new(x, y, z)
hitMarker.Size = Vector3.new(1, 1, 1)
hitMarker.Anchored = true
hitMarker.BrickColor = BrickColor.Red()
hitMarker.Parent = workspace
else
print("No intersections found.")
end
By the way, you’re seeing two sets of variables for origin and direction. The one that is just a markup is the old hitbox of the mesh that works for Raycast, but I want the new updated hitbox so I can get the X, Y, Z vector that the raycast is supposed to detect as it passes through the MeshPart.
I think I’m close to making it work. Thanks to anyone who is helping me with this.