Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a part move to a certain position?

Asked by 8 years ago

So I'm making an auto turret that spawns in a bullet every second, and fires the bullet toward the direction of the nearest NPC. However, I can figure out how to do this. I've made so many scripts attempting to solve this problem that It would be useless to show you them (as none of them worked in any way). So, how would I do this? Basically, this is the script I keep using as a start point:

local Part = script.Parent
local newPos = Part.Position + game.Workspace.Base.target.Position 
local Time = 1
local Increment = 0.5 
local Debounce = false

local Diff = newPos - Part.Position
local Mag = Diff.magnitude 
local Direction = CFrame.new(newPos).lookVector

    for n = 0, Mag, Increment do
        Part.CFrame = Part.CFrame + (Direction * Increment)
        wait( (Time/Mag) * Increment )
    end

The script is set to aim at a part named "target". The bullet will move when it spawns in, however it only moves directly forward, it doesn't move towards the target. Help?

NOTE: The script that moves the bullet is in the bullet itself, not in the turret (don't ask me why, I just kinda made it that way for some reason). All the script really does is move the bullet in a certain direction until it reaches its destination.

1 answer

Log in to vote
-1
Answered by 8 years ago

i suggest try to do it with the turret and that might work

Ad

Answer this question