Project trajectory path visual bugging out

Is there a reason why its only glitching when I jump and walk sideways?

local tool = script.Parent
local verticalBoost = 0

local TRAVERSE_TIME = 0.5
local MAX_VERTICAL_BOOST = 0.5
local VELOCITY = 75
local PATH_STEPS = 100
local GRAVITY = Vector3.new(0, -workspace.Gravity, 0)

RunService.RenderStepped:Connect(function()
    workspace.PathPoints:ClearAllChildren()

    --Adjust vertical boost
    local cameraYOrien = math.deg(camera.CFrame.Rotation:ToOrientation())
    if cameraYOrien > 0 then
        verticalBoost = MAX_VERTICAL_BOOST
    else
        local ratio = math.clamp(1 - (math.abs(cameraYOrien) / 80), 0, 1)
        verticalBoost = MAX_VERTICAL_BOOST * ratio
    end

    --Get throw directiron
    local cameraLookVector = camera.CFrame.LookVector
    local rootPartLookVector = humanoidRootPart.CFrame.LookVector

    local xDirection = rootPartLookVector.X
    local yDirection = cameraLookVector.Y + verticalBoost
    local zDirection = rootPartLookVector.Z
    local direction = Vector3.new(xDirection, yDirection, zDirection).Unit

    local initialPos = tool.Handle.Position
    local initialVel = (direction * VELOCITY)

    --Create path visual
    local previousPos = tool.Handle.Position
    for i = 0, PATH_STEPS  do
        local t = i / (PATH_STEPS)

        local deltaPos = (0.5 * GRAVITY * (t^2)) + (initialVel * t) + initialPos

        --Create impact position visual
        raycastParams.FilterDescendantsInstances = {workspace.PathPoints, character}
        local raycast = workspace:Raycast(previousPos, deltaPos - previousPos, raycastParams)
        if raycast then
            local hitVisual = script.Hit:Clone()
            hitVisual.Position = raycast.Position
            hitVisual.Parent = workspace.PathPoints

            return
        else
            previousPos = deltaPos

            local point = script.Path:Clone()
            point.Position = deltaPos
            point.Parent = workspace.PathPoints
        end
    end
end)

I don’t know the exact reason but shift-lock has the tendency to be a bit choppy when using it in a RenderStepped loop.

One quick way to fix would be to use the camera X and Z while shift-lock is enabled. You can add an if statement to your direction calculation like so:

...
local xDirection = rootPartLookVector.X
local yDirection = cameraLookVector.Y + verticalBoost
local zDirection = rootPartLookVector.Z

-- Check for shift-lock
if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
	xDirection = cameraLookVector.X
	zDirection = cameraLookVector.Z
end
	
local direction = Vector3.new(xDirection, yDirection, zDirection).Unit
...

It isn’t glitching, it’s what your AI coded it to do.
You are using HumanoidRootPart.CFrame.LookVector as a reference in your code.


When a Roblox character jumps while moving laterally (strafing), the physics engine often applies a slight tilt or rotation to the HumanoidRootPart to align with the direction of momentum. Because the code extracts the X and Z components directly from this part:

  1. Stationary/Walking: The rootPartLookVector remains relatively stable and aligned with the character’s forward facing.
  2. Jumping and Moving: The rootPartLookVector shifts as the character’s body tilts or rotates mid-air. This changes the direction variable, causing the visualizer to pivot.

To maintain a consistent path regardless of character animation or tilt, derive the horizontal direction from the Camera instead of the HumanoidRootPart.

Replace the direction logic with:

local cameraCFrame = camera.CFrame
local xDirection = cameraCFrame.LookVector.X
local yDirection = cameraCFrame.LookVector.Y + verticalBoost
local zDirection = cameraCFrame.LookVector.Z
local direction = Vector3.new(xDirection, yDirection, zDirection).Unit

A few tips for you:

  1. You could look into Spherecast to simulate an object being thrown relative to size, so that it doesn’t “accidentally” clip an edge.
    This is commonly done with round objects or otherwise large objects.
  2. You could also calculate velocity inheritance from the character to get a “truer” projection on the trajectory.
  3. Your current code divides the projection into PATH_STEPS (100). If the TRAVERSE_TIME is long, each segment covers a large distance.
    The Issue: A segment might start on one side of a thin wall and end on the other.
    The Fix: Calculate the segment length based on a fixed time delta (e.g., 0.1 seconds) rather than a fixed number of steps.

We really can’t help without accusing of AI now? My bad that my math is bad and I like to write comments. Also your solution doesn’t work, the path still tilts a little regardless if I use the root part or camera as my base.

There’s nothing wrong with using AI; it’s not something to be embarrassed by. It has unicode watermarks and the styling, and if you wrote the code yourself you’d note this line:

local initialVel = (direction * VELOCITY)

Which is used to calculate the projection.
Like I explained here:


If your goal is not to have it move depending on character movement, you need to strip the roll components and velocity lines and do something like this:

local tool = script.Parent
local verticalBoost = 0
local TRAVERSE_TIME = 0.5
local MAX_VERTICAL_BOOST = 0.5
local VELOCITY = 75
local PATH_STEPS = 100
local GRAVITY = Vector3.new(0, -workspace.Gravity, 0)

RunService.RenderStepped:Connect(function()
    workspace.PathPoints:ClearAllChildren()

    -- Adjust vertical boost
    local cameraYOrien = math.deg(camera.CFrame.Rotation:ToOrientation())
    if cameraYOrien > 0 then
        verticalBoost = MAX_VERTICAL_BOOST
    else
        local ratio = math.clamp(1 - (math.abs(cameraYOrien) / 80), 0, 1)
        verticalBoost = MAX_VERTICAL_BOOST * ratio
    end

    -- Get throw direction (strip camera roll)
    local pitch, yaw, roll = camera.CFrame:ToOrientation()
    local cleanCFrame = CFrame.fromOrientation(pitch, yaw, 0)
    local xDirection = cleanCFrame.LookVector.X
    local yDirection = cleanCFrame.LookVector.Y + verticalBoost
    local zDirection = cleanCFrame.LookVector.Z

    local direction = Vector3.new(xDirection, yDirection, zDirection).Unit
    local initialPos = tool.Handle.Position
    local initialVel = direction * VELOCITY

    -- Create path visual
    local previousPos = tool.Handle.Position
    for i = 0, PATH_STEPS do
        local t = i / PATH_STEPS
        local deltaPos = (0.5 * GRAVITY * (t^2)) + (initialVel * t) + initialPos

        raycastParams.FilterDescendantsInstances = {workspace.PathPoints, character}
        local raycast = workspace:Raycast(previousPos, deltaPos - previousPos, raycastParams)
        if raycast then
            local hitVisual = script.Hit:Clone()
            hitVisual.Position = raycast.Position
            hitVisual.Parent = workspace.PathPoints
            return
        else
            previousPos = deltaPos
            local point = script.Path:Clone()
            point.Position = deltaPos
            point.Parent = workspace.PathPoints
        end
    end
end)

Using the camera’s lv does stabilize a lot but theres still micro stutters tho I’ve figured something out. Thanks!

I am glad that I could be of help :+1: