Is it possible to add a value to a CFrame Axis directly?

I am trying to make the head of an IK-robot tween up and down while moving. However, the tween pauses other CFrame actions done on other scripts. That’s why I want to know if it’s possible to add value to an Axis (ex: Z-Axis) specifically and not modify any other Axis.

What it looks like:
https://i.gyazo.com/cd351a9f8956ed1ce3424502e4a73e97.mp4

As you might’ve noticed, the robot stops moving briefly every time the tween plays.

My Code:

local TweenService = game:GetService("TweenService")

local tweenInfoUp = TweenInfo.new(0.75, Enum.EasingStyle.Linear)
local tweenInfoDown = TweenInfo.new(0.25, Enum.EasingStyle.Linear)

module.TweenObject = function(Object, tGoals)
	local UpTween = TweenService:Create(Object,tweenInfoUp,{CFrame = tGoals.CFrame + Vector3.new(0,5,0)})
	local DownTween = TweenService:Create(Object,tweenInfoDown,{CFrame = tGoals.CFrame})
	local upTweenHead = TweenService:Create(Object.Parent.Head, tweenInfoUp, {CFrame = Object.Parent.Head.CFrame + Vector3.new(0, 2.5)})
	local DownTweenHead = TweenService:Create(Object.Parent.Head,tweenInfoDown,{CFrame = Object.Parent.Head.CFrame})
		
	UpTween:Play()
	upTweenHead:Play()
	UpTween.Completed:Connect(function()
		DownTween:Play()
        DownTweenHead:Play()
	end)
end

The CFrame actions in another script:

while wait(0.001) do
	Bot.Head.CFrame += Vector3.new(0,0,0.1)
end

Yes, but not using TweenService due to the unfortunate choice of having TweenService only work for tweening properties and having no way of defining custom animations.

I have a WIP animation library that combines the useful tween styles/directions with the ability to use any logic whatsoever, making something like a tweened helix path possible:

Anim.rbxm (5.0 KB)

local anim = Anim.new(TweenInfo.new(3, Enum.EasingStyle.Bounce), function(v)
	local angle = math.pi*2*v * 2
	p.CFrame = CFrame.new(math.cos(angle)*r, v * 10, math.sin(angle)*r)
end)
anim:Play()

Animation2

Or to show how different animations can affect the same part without issues with this approach:

local anim1 = Anim.new(ti, function(v)
	local angle = math.pi*2*v * 2
	p.CFrame = CFrame.new(math.cos(angle)*r, p.Position.Y, math.sin(angle)*r)
end)
anim1:Play()
local anim2 = Anim.new(ti, function(v)
	p.CFrame = CFrame.new(p.Position.X, v*10, p.Position.Y)
end)
anim2:Play()

This only works because the two anims affect things that are independent, namely the X/Z axes and the Y axis, respectively. If you e.g. wanted anim2 to affect the X axis, that wouldn’t work and you’d have to either combine the two animations or use the second parameter that gets passed to the callback, which is the change in value since the last call (-ish).

Although to be fair I wouldn’t use an approach like this in the first place, the whole idea of animations that “know” where to go like 1 or 2 seconds into the future goes against the idea of dynamic, procedural animations. Maybe you could try using tweens/animations for the feet only, and then set the CFrame of the head to be the average/midpoint of the two “elbow” joints?

Or perhaps the midpoint of the feet positions, plus some vertical offset?

2 Likes

Thank you SO MUCH for the resource and advice. Having the head be the midpoint of the two feet positions is definitely a better approach.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.