Position still going towards the same axis even after changing orientation (CFrame)

I want this object to move forward in the direction it’s looking towards

However when it spins (towards the mouse in my case) it doesnt move forward towards it it still goes in the same direction.

This is how I have everything set up on the explorer.

Explorer

The local Script:

local player = game.Players.LocalPlayer


    local mouse = player:GetMouse()

    local TurretUnion = game.Workspace.Turret.TurretS

    local unit = (mouse.Hit.Position-TurretUnion.Position).Unit

    local cross = unit:Cross(Vector3.new(0,1,0))

    local model = game.Workspace.Turret

    while wait() do

    print("- -")

    print("-_-_-_-_-_-_-_-_-_-_-_-_")

    TurretUnion.CFrame = CFrame.new(TurretUnion.Position, Vector3.new(mouse.Hit.Position.X,TurretUnion.Position.Y,mouse.Hit.Position.Z))

    TurretUnion.Position = TurretUnion.Position + Vector3.new(0, 0, 3)

    print("Current Position:")

    print(mouse.Hit.Position)

    print("Current Orientation:")

    print(game.Workspace.Turret.TurretS.Orientation)

    end

how can I change this line to fix this?

TurretUnion.Position = TurretUnion.Position + Vector3.new(0, 0, 3)

-Hope you can help.

Yeah I believe this is the issue, it goes in the same direction because this direction is defined as (0,0,3).

You can resolve this by making this change in vector relative to where the turret is looking using the turrets CFramr.LookVector property.

So try replacing it with

+TurretUnion.CFrame.LookVector*3

1 Like