Smooth Turn using TweenService

I’ve been wondering if there is a way to make a smooth turn by using Tween Service

In the Image bellow you can see i have 3 Points (A , B , C) and i want my part(the Green Cube) to move from Point A to Point B and from Point B to point C. That alone is easy with Tween Service but i wanna know if there is a way for it to turn smoothly (basically follow the Black Line) and also turn the cube itself in the process to face towards the direction its turning to (the purple line on the cube is the direction its facing)

does anyone know if this is possible using tween service and if not is there any way to do it?

image

1 Like

i’m pretty sure, here you will certainly have to use:

math.cos

or

math.sin

1 Like

I don’t think making these curves with tween service is possible, though you can experiment with lerping, you can either use trigonometry, basically what @hunder305 recommended, or use bezier curves. But both require some type of lerping/Run Service loop.

Heres an example with Bézier curves, you also need a control part, because Bézier curves require 3 or more points,

local RunService = game:GetService("RunService")

local part = workspace.Part 
local start = part.Position 
local control = workspace.Control.Position 
local target = workspace.Target.Position

local duration = 5
local startTime = tick() 

RunService.Heartbeat:Connect(function()
	local elapsed = tick() - startTime
	local t = math.clamp(elapsed / duration, 0, 1) 

	local position = (1 - t)^2 * start 
		+ 2 * (1 - t) * t * control 
		+ t^2 * target

	part.Position = position

	if t == 1 then
		return
	end
end)

1 Like

or, you can create an attachment in front of the part, then make it TweenPos towards that attachment and make another script that rotates the part

oh yuh, i still need some more scripting skills

i don’t even know how to fully use math dot

I think this is more simple than Dot and Cross product, though Dot and Cross also aren’t that hard to understand. Watch some general YouTube tutorials about Dot and Cross, you’ll get what they do, but from what I understand:

Dot: Measures how much one vector points to another
Cross: Finds the vector perpendicular to the 2 provided(Only in 3D space.)

You can’t do this with TweenService, at least, not directly.

What you’re describing here is a Bezier Curve.

You need a function like this which creates a bezier using CFrames (double check the spelling).


function bezier(a : CFrame, b : CFrame, c : CFrame, t : number)

 local v1 = a:Lerp(b, t)

 local v2 = b:Lerp(c, t)

 return v1:Lerp(v2, t)

end 

Use this function to interpolate a CFrame.
Second, you can use TweenService to interpolate the value of a NumberValue object from 0 to 1.

Each time the NumberValue updates, you run this code.

NumberValue.Changed:Connect(function()

 Part.CFrame = bezier(start, middle, goal, NumberValue.Value)

end)

This code may not be perfect but I hope it gets the idea across, obviously you will have to make some edits to make it work in your project.

i meant dot like this → .

Oh…

I guess im overthinking it, my apologies :upside_down_face:

no needa appologize man