So when I started working with Leadwerks, my goal was to make a 2.5D platformer. I'd been making some great progress in that regard, mainly by using Pivots to create a movement path (pressing a direction makes the player turn and move toward one of two pivots, and once a pivot is reached the next/previous set of pivots in the sequence are swapped in).
Now one issue had become a big problem, and it's one which I've seen others here struggle with as well: being pushed off-path by objects in the player's path. This problem nearly made me scrap my progress and switch to a different engine... But I found out how to fix it!
This method doesn't exactly "lock" the movement axis, but rather applies a sort of rubberband effect when the player gets too far off-course. The code isn't as streamlined as it could be, since I only just made it, but it works and I want to share it with others who may have been dealing with the same problem.
If you have any questions, feel free to ask!
distanceRight = self.entity:GetDistance(self.rightPath)
distanceLeft = self.entity:GetDistance(self.leftPath)
local correctionP = Vec3(self.entity:GetPosition(true).x - self.leftPath:GetPosition(true).x, 0, self.entity:GetPosition(true).z - self.leftPath:GetPosition(true).z)
local correctionW = Vec3(self.rightPath:GetPosition(true).x - self.leftPath:GetPosition(true).x, 0, self.rightPath:GetPosition(true).z - self.leftPath:GetPosition(true).z)
correctionP = correctionP / correctionP:DistanceToPoint(Vec3(0, 0, 0))
correctionW = correctionW / correctionW:DistanceToPoint(Vec3(0, 0, 0))
correctionP:Normalize()
correctionW:Normalize()
local correctionD = (correctionP * distanceLeft)
if correctionD:DistanceToPoint(correctionW * distanceLeft) > 0.1 then
local correction = Vec3((correctionW.x * distanceLeft) - correctionD.x, 0, (correctionW.z * distanceLeft) - correctionD.z)
correction = correction * self.moveSpeed
self.entity:AddForce(correction, true)
end