How can I make a character strictly follow a path?

I am trying to move a character between rooms in a 2d top-down game. Here is some background…






So yeah. This is not enemies pathfollowing, and going off a path. This is just translating a character across an imaginary curved line. I am not sure of the best way to do that.

2 Likes

Hi. If you use Math you can plot a curve and follow that.

2 Likes

@Deaton’s suggestion is what I would do too, you could use a cubic bezier curve for it, something like:

local function bezier(t, p0, p1, p2, p3)
    local tp = 1 - t
    return tp*tp*tp*p0 + 3*tp*tp*t*p1 + 3*tp*t*t*p2 + t*t*t*p3
end

You pass in the points according to the wikipedia page, and let t vary from 0 to 1 to go over the curve. It might not fit your shape perfectly or keep a constant speed over the curve, but I bet it would be sufficient. It’s also really flexible for other paths. Just tweak the p1 and p2 to change the curve. Using draw_line you can also plot it so you don’t have to watch the thing move over it.

10 Likes