Performant alternative to tweens?

Currently I am working on a game where players have to jump over lanes of traffic to get to the other end. Currently I am using TweenService on the client to get a car from one end to the other. However, on lower end devices this can result in FPS drops due to the amount of tweens playing at once. This makes the tweens slower which ruins the gameplay. Is there an alternative that can solve this problem?

2 Likes

you can use cframe if you want to move the vehicles automatically

1 Like

How would this be anymore performance efficient than tweening?

Could you show a video of what the game is like? Have you done benchmarks to make sure that it is really tweening causing the issues?

I am unable to record a video of the game at the moment but here is the game link. Dodge Traffic! - Roblox

It could be the rapid cloning of the cars. You could try making a “loop” where you have a bunch of cars and tweens that get recycled over and over. You could also try posting your code in #help-and-feedback:code-review to get feedback and potential optimizations. Are these models or just a single meshpart?

Here

are you sure the performance drops are actually from the tweens playing? tween lag is usually from the sheer amount of un deleted loose tweens that are doing nothing other than taking up ram (you can directly use the :Delete() function on the completed tweens as they count as instances). also using cframes would actually be a better alternative performance wise than tweens.

Each vehicle is a model of several MeshParts welded together.

I am already deleting all tweens once they are done. What would be the best way to animate using CFrame? Simply using SetPrimaryPartCFrame every frame?

you can make a loop which adds the models position

you can move the entire welded assembly with a cframe if all of the side parts are not anchored and you don’t move it by setting the position, setting the position of one of two welded parts breaks the weld even if the other part is not anchored so use cframe instead of it.

1 Like

just adjust the anchored base parts cframe and all the un anchored welded parts will follow

1 Like

i recommend u to use “BodyVelocity” i would do that with it. its easy to use all u need to do is adding a “BodyVelocity” inside a part. then set the velocity to…
part.CFrame.LookVector * 50
hope this helps…
edit: asol parts must be unanchored

Physics are much worse on performance than using CFrames. I was using BodyVelocities previously and they were horrible.

they can be horribe sometimes. did you tryed to use CFrame:Lerp()?

edit, this may need a goal position… and parts should be anchored

1 Like

I tried this solution and before I was getting activity of 1-2%, now it’s upwards of 17%.image
This is the code I am using.

local function RenderStepped(DT)
	for i, v in pairs(MovingCars) do
		if not v.Parent then
			table.remove(MovingCars,i)
			continue
		end
		v.PrimaryPart.CFrame *= CFrame.new(0,0,-(v.Lane.Value:GetAttribute("Speed")*DT))
	end
end

first, you should only reserve code for render stepped if it truly needs to be there, an example of this would be camera movement and first person arms(fps game), try putting it in heartbeat instead. id also recommend only moving cars you can actually see

You can lerp the CFrame , so that you won’t have to create a lot of tween objects and play.
Example :

local x = 2
local TargetCFrame = ...
local function Update(delta)
  Part.CFrame = Part.CFrame:lerp(TargetCFrame,delta * x)
end
RunService.RenderStepped:Connect(Update)

This is a small example on how you could do it.

1 Like

if you where to only move cars you can actually see then you would have to save the z position as a value for each cars instead of adjusting the cframe each frame. so like each car has a forward position value and you add to that value every frame, then you set the cframe to CFrame.new(xpos,ypos,currentZdistance) as an example.

1 Like