#Raycast issue with placement system

1 messages · Page 1 of 1 (latest)

spring notch
#

Im making a placement system for my game. It starts by raycasting 10 studs in front of your hrp to avoid going through walls, it then goes down 20 studs to clip to the ground, only problem is sometimes when you jump it moves the object up above you which shouldnt be happening. When it goes up on the wall it also turns green meaning its viable plcement.

local BUFFER = 1


tool.Equipped:Connect(function()
    
    
    local tempModel : Model = powerupModels:FindFirstChild(powerupname):Clone()
    tempModel.Parent = workspace.CurrentCamera
    transformMaid:GiveTask(RunService.Heartbeat:Connect(function()
        if not hrp or not tempModel then return end
        
        
        --raycast in front display offset, then down 10 studs and place there
        
        --front raycast
        local baseY = hrp.Position.Y - 2
        local startPointForward = hrp.Position + Vector3.new(0,baseY,0)
        local directionForward = hrp.CFrame.LookVector * DISPLAY_OFFSET
        
        local forwardHit = utilities.raycastModule(startPointForward, directionForward, {char})
        
        local forwardPos
        if forwardHit then --stop before wall
            forwardPos = forwardHit.Position - hrp.CFrame.LookVector * BUFFER
        else
            forwardPos = hrp.Position + hrp.CFrame.LookVector * DISPLAY_OFFSET
        end
        
        local downOrigin = forwardPos + Vector3.new(0,DISPLAY_OFFSET,0)
        local downDirection = Vector3.new(0,-20,0)
        
        local GroundHit = utilities.raycastModule(downOrigin, downDirection, {char})
        
        if GroundHit then --can place ere
            tempModel:PivotTo(CFrame.new(GroundHit.Position))
            tempModel.Wall.Color = Color3.new(0,1,0)
        else --cant place
            tempModel:PivotTo(CFrame.new(forwardPos))
            tempModel.Wall.Color = Color3.new(1,0,0)
        end
            

    end))
    
end)```
scenic quail
#

why dont u make it follow the mouse and prevent it from going up and down

#

the issue I think is that the raycast is going beyond the wall over the roof when u jump and down onto the roof

spring notch
#

ill add some trails to debug

scenic quail
#

when the player jumps

#

that ray follows I think

spring notch
#

but the hrp is never going that high

#

ok wait

#

i could either find out how to fix this or just disable the heartbeat when theplayer is not grounded

scenic quail
#

ohhh

#

what happened when u walk into the wall

spring notch