Help with smooth turning on the x axis while y and z axis are moving

I need to make the turn from going up, then going straight, up or down look good and smooth, similar to video 1, but I need to do it to my game, video 2

Video 1

Video 2

Video 1 looks fine, but with mine, it just kind of floats in the air a bit. I’m not sure if I need to do a bezier curve or not.

code

local function UpHillTurn(EnemyData, Position, DeltaTime, Node)
	local X, Y, Z = EnemyData.CFrame:ToOrientation()
	EnemyData.UpHillDeltaTime += DeltaTime
	if EnemyData.UpHillDeltaTime >= (3 / EnemyData.Speed) then
		EnemyData.UpHillDeltaTime = 0
		EnemyData.UpHillStatus = 0
		return CFrame.fromOrientation(X, Y, Z)
	else
		EnemyData.UpHillStatus = 1 - EnemyData.UpHillDeltaTime / (3 / EnemyData.Speed)
		return CFrame.fromOrientation(CFrame.new(GetNode(Node - 1, EnemyData.Path).Position, GetNode(Node, EnemyData.Path).Position):ToOrientation() * EnemyData.UpHillStatus, Y, Z)
	end
end

It all works fine, just not sure whether I should do a bezier curve or edit it?

5 Likes

So if I’m correct, and you want to tween the orientation…

You can save the Y and Z values as a variable, create a NumberValue for the X, and then tween that NumberValue to your target X, and then create a GetPropertyChangedSignal connection to to adjust the full orientation of the object whenever the X value changes.

local NumberValue = instance.new("NumberValue")
local OriginalY = Object.Orientation.Y
local OriginalZ = Object.Orientation.Z

NumberValue.Value = OriginalX -- Make this whatever the original X orientation is.
TweenService:Create(NumberValue, TweenInfo, {Value = TargetX}):Play()

NumberValue:GetPropertyChangedSignal("Value"):Connect(function()
       ObjectThing.Orientation = vector3.new(NumberValue.Value, OriginalY, OriginalZ)
end)
1 Like

You can save the values in a table for more consistency.

local NumberValue = instance.new("NumberValue")
local OriginalYZ = {Object.Orientation.Y,Object.Orientation.Z}

NumberValue.Value = OriginalX -- Make this whatever the original X orientation is.
TweenService:Create(NumberValue, TweenInfo, {Value = TargetX}):Play()

NumberValue:GetPropertyChangedSignal("Value"):Connect(function()
       ObjectThing.Orientation = vector3.new(NumberValue.Value, OriginalYZ[1], OriginalYZ[2])
end)
2 Likes

Any doubts then just reply to this post

1 Like

Now that I think about this, it is just basically lerp, but I need help with deciding what I should do. Title has been changed and description too

1 Like

Bezier curves seems unnecessary here, I’m fairly sure lerping the cframe will smoothen the rotation pretty well.

1 Like

what should I use though? it looks bad

1 Like

Where’s the code in which you set the CFrame? Also, your second vid doesn’t load

1 Like

Please expand, also to fix the vid just reload the page, if that dont work ill make a new one. Do you mean how I get the EnemyData.CFrame?

1 Like

You don’t really need to know that, i just need opinions kind of. Its a disscussion.

1 Like

You don’t do discussions in the Scripting Support page.

1 Like

It’s not really a discussion though, I just need people’s opinions and what I should / could do to improve it

Still not suitable in the Scripting Support page.

This is for needing “support in your script”, not to get peoples’ opinions on improvement generally.

1 Like

Changed it to suit the appropriate category

1 Like

Well I did give my opinion, and it was you who asked to expand so I assumed I can just demonstrate how it would work in code terms and be done with it

Fixed it, my code was just bad for adjusting the y

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