Triangle is not drawing properly

the corner is the vertices of the object that the raycast found, when I draw a triangle, a square appears on top? And yes, i’m suck at math

here is the part of a script.

local Canvas = CanvasModule.new(script.Parent.MainFrame, Vector2.new(50,50), false, false)
local Params = RaycastParams.new()
        Params.FilterType = Enum.RaycastFilterType.Include
        Params.FilterDescendantsInstances = LevelWorkspace:GetChildren()

        local ViewRayOrigin = CameraPart.Position
        local RayAngle = CFrame.Angles(0, -math.rad((Count * SettingsModule.FieldOfView) / SettingsModule.Resolution), 0)
        local ViewRayDirection = (CameraPart.CFrame * RayAngle).LookVector * SettingsModule.RenderDistance

        local ViewRay = workspace:Raycast(ViewRayOrigin, ViewRayDirection, Params)
        if ViewRay and ViewRay.Instance:IsA("BasePart") and ViewRay.Instance.Transparency < 1 then
            local HitPart = ViewRay.Instance

            local Corners = {
                [1] = Vector3.new(HitPart.Position.X + (HitPart.Size.X / 2), HitPart.Position.Y + (HitPart.Size.Y / 2), HitPart.Position.Z + (HitPart.Size.Z / 2)),
                [2] = Vector3.new(HitPart.Position.X + (HitPart.Size.X / 2), HitPart.Position.Y + (HitPart.Size.Y / 2), HitPart.Position.Z - (HitPart.Size.Z / 2)),
                [3] = Vector3.new(HitPart.Position.X + (HitPart.Size.X / 2), HitPart.Position.Y - (HitPart.Size.Y / 2), HitPart.Position.Z + (HitPart.Size.Z / 2))
            }


            local Distance = (ViewRayOrigin - ViewRay.Position).Magnitude

            local RayAngleX, RayAngleY, RayAngleZ = RayAngle:ToEulerAnglesXYZ()    
            local CameraAngleY = math.rad(-CameraPart.Orientation.Y)    

            Distance = Distance * math.cos(RayAngleY - math.rad(CameraAngleY))
            Canvas:DrawTriangle(Vector2.new(Corners[1].X, Corners[1].Y), Vector2.new(Corners[2].X, Corners[2].Y), Vector2.new(Corners[3].X, Corners[3].Y), HitPart.Color, false)

I have used that raycast engine before or a raycast engine that looks like that and it is because of the way that it raycasts. it raycasts from the center of the player part and it does not support height. In other words, the wedge gets raycasted at to the center of the wedge’s height, so the player sees half of it and it turns into a cube because the engine does not support height and therefore it is seen as a normal cube part.

1 Like

So I need to raycast every pixel to get the height?

Possibly. There might be another way, but I don’t know it. The creator of the engine is making a new version, but I am unsure if it supports wedges.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.