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

How to make a block move to a player at a fixed speed? [SOLVED]

Asked by 4 years ago
Edited by DeceptiveCaster 4 years ago

This is my code:

local maths = 10
local limb = "Head"
wait(5)
repeat
    local p1 = script.Parent.nearest.Value
    if p1 ~= "nil" then
        local player = game.Workspace[p1]
        local pos = script.Parent.Position
        local ppos = player[limb].Position
        -- X
        local x1 = pos.X - ppos.X
        local x2 = x1 / 10
        -- Y
        local y1 = pos.Y - ppos.Y
        local y2 = y1 / 10
        -- Z
        local z1 = pos.Z - ppos.Z
        local z2 = z1 / 10
        -- hunt down the player

        script.Parent.energy.Value = script.Parent.energy.Value - 1     
        script.Parent.Position = script.Parent.Position - Vector3.new(x2,y2,z2)

    end
    wait(0.01)
until nil

The problem here is, no error, is that it makes the brick move to the player, but since it divides the distance by 10 it will get slower as it gets closer to the player, and faster as the player moves away, making an infinite stalemate if the player walks away. I was wondering if a fixed speed was possible.

Is there a CFrame property I'm missing?

1 answer

Log in to vote
0
Answered by 4 years ago

Fixed, I'm gonna use bodyposition.

0
Yeah body postion is the way to go, it has MaxVelocity property. sleazel 1287 — 4y
Ad

Answer this question