#help with tram

1 messages · Page 1 of 1 (latest)

summer basin
#

how would i go on about making a tram system the same as black mesa / half life? so it actually can move nicely at curves

magic bane
#

Tweening between points that are just parts or moving it along bezier curve

#

I would prefer the second one

magic bane
#

I started with something like this when I began creating my rendered tank tracks

local RunService = game:GetService("RunService")

-- points of the curve
local p0 = Vector3.new(0, 0, 0)      -- start point
local p1 = Vector3.new(0, 10, 20)    -- middle point (like height/top)
local p2 = Vector3.new(20, 0, 40)    -- end point

local part = workspace:WaitForChild("part")    -- the part that moves

local duration = 5    -- tiem to complete the movement

local function bezier(t, p0, p1, p2)
    local u = 1 - t
    return (u*u) * p0 + 2*u*t * p1 + (t*t) * p2
end

RunService.RenderStepped:Connect(function()
    local elapsed = tick()
    local t = (elapsed % duration) / duration

    local pos = bezier(t, p0, p1, p2)

    local nextPos = bezier(math.min(t + 0.01, 1), p0, p1, p2)
    local dir = (nextPos - pos).Unit
    part.CFrame = CFrame.lookAt(pos, pos + dir, Vector3.new(0, 1, 0))    -- this is updating the position
end)

It's just a bunch of calculations that are fairly easy when you get into it