I’m making this frog follow a bezier curve
Steps so far:
- Find the start, end, and middle points
- Generate x amount of waypoints
- Make character traverse waypoints
the problem right now is with step 3, I’ve tried regular cframing, alignposition, and tweening
tweening is the best solution so far, and is what I used in the video above
– tweening character
local function jump(jumpDistance, jumpHeight, jumpTime, wayPointCount)
if jumping then return end
jumping = true
local tweenInfo = TweenInfo.new(jumpTime/wayPointCount, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local startPosition = humanoidRootPart.Position
local endPosition = humanoidRootPart.Position + humanoidRootPart.CFrame.LookVector * Vector3.new(jumpDistance, 1, jumpDistance)
local ray = Ray.new(endPosition + Vector3.new(0, 50, 0), Vector3.new(0, -600, 0))
local _, finalEndPosition = workspace:FindPartOnRayWithIgnoreList(ray, {character})
finalEndPosition = finalEndPosition + Vector3.new(0, .5, 0)
local middlePosition = startPosition:Lerp(finalEndPosition, .5) + Vector3.new(0, jumpHeight, 0)
frogJumpAnimation:Play()
frogJumpAnimation:AdjustSpeed(.5)
local function getWayPoints()
local wayPoints = {}
for i = 1, wayPointCount do
local alpha = i/wayPointCount
local waypoint = (1 - alpha)^2 * startPosition + 2 * (1 - alpha) * alpha * middlePosition + alpha^2 * finalEndPosition
wayPoints[i] = waypoint
end
return wayPoints
end
local wayPoints = getWayPoints()
table.insert(wayPoints, finalEndPosition)
if DEBUG_VISUALS then
coroutine.wrap(function()
for _, waypoint in ipairs(wayPoints) do
local newDebugPart = debugPart:Clone()
newDebugPart.Position = waypoint
newDebugPart.Parent = workspace
Debris:AddItem(newDebugPart, 4)
end
end)()
end
humanoidRootPart.Anchored = true
frogWalkAnimation:Stop()
for i = 1, #wayPoints do
local waypoint = wayPoints[i]
local x, y, z = humanoidRootPart.CFrame:ToOrientation()
local goal = CFrame.new(waypoint) * CFrame.fromOrientation(x, y, z)
local tween = TweenService:Create(humanoidRootPart, tweenInfo, {CFrame = goal})
tween:Play()
tween.Completed:Wait()
end
humanoidRootPart.Anchored = false
frogJumpAnimation:Stop()
jumping = false
end
The problem is that it isn’t 100% smooth with all speeds, and the jumpTime isn’t accurate, and I really need both
the jumpTime needs to be accurate so I can sync animations with the jump
is there a better way to do this?
BTW the code is a bit messy because I’m just trying to get this to work properly, and then I’m going to polish it