When lerping several objects game lags an incredible amount

I have a bunch of cannons the lerp to and from a rotation, when doing this the entire game loses a metric ton of frames, is there any more efficient ways of doing this without lerping every single event tick or is there something better than lerp as once is starts it never fully reaches its end goal and just continues lerping into smaller and smaller decimals.

TL;DR any way to make several lerps any more efficient or is there any other way to actively change between lerped rotations of several objects

1 Like

Can you show the code for one cannon? Unless you have 1000s of cannons, I’m suspecting the code a bit… :wink:

( especially reading the second part )

1 Like

It should look something like this

With a lerp on a timeline, you need to calculate the start and end points before running the timeline.

Lerp doesn’t work on pure tick. That would be finterp, and a cannon doesn’t move like that.

2 Likes

so the timeline is simply goin from 0-1 over x amount of time if im reading it correctly

yip

1 Like

There are other ways, depending on how you want the cannons to behave.

1 Like


First half ^


Second half^ (continues at white arrow on the left)

What im plannin to potentially do as well is to make it so that the first 6 in the array/set of the cannons do the rotation and the rest follows suit with set rotation but i dont know if it changes anythin optimisation wise

1 Like

^ here is the cannon fuff forgot to hit reply

implemented this somewhat

it is a lot better but when it actually interpolates it creates a much more severe lag spike

Yeah, it’s because you’re calling something that can do the whole cannon movement, on tick. ( it only needs to be called once ).

Maybe tell me what you want the cannons to do? I can understand you want to be able to pan left and right. What’s the adjust width thing?

Also, why bother coding this whole thing, when you can make a cannon blueprint, and that’s it?

For instance, just to turn from an axis input on Z, you can use

so basically the cannons are managed by a middeck blueprint that adjusts the rotation of all the cannons through scroll wheel input and then smoothly rotates towards the desired cannon fire width to then shoot cannonballs, depending on how close to centre of the ship a cannon will rotate only a set amount through a function called ration calculator (the closer to centre the less od the rotation target it will have)

image_2022-04-26_151938801
This is the average amount of cannons we expect players to have (the same amount on the other side)

mouse button clicks to fire each respective side

the player is able to actively change their desired width of the cannon at any time depending on the situation if there are several enemies for spread fire or just one for on powerful concentrated shot

the only thing that the cannon blueprint should manage is whether or not to fire to keep it simple

image_2022-04-26_152713913
smallest firing width
vs
widest firing width
image_2022-04-26_152802305

Ok, don’t do it with blueprints :slight_smile:

I need to re-think.

Haven’t seen that many cannons on a ship, till now… :smiley:

I’m thinking of instanced static meshes. Gimme a while…

yee no worries the timeline addition did improve the performance post cannon rotation, but when it is actually rotating the game does not enjoy existence XD

the cannons are made with the Add Child Actor Component that then is placed into a child actor set corresponding to which side it is on (Right and Left)

do you think simply having the lerp occurring on the bottom row only and then having the rest of cannons on subsequent levels just follow the rotation of the cannons on the bottom row using set rotation?

Child actor components are really finicky to manage. I think you’re better of with blueprints frankly.

It really depends how involved the shoot animation is.

If it’s very simple, you can do it with ISMs, otherwise you’ll need blueprints.

mmmm aighty thankyou for the help ill report back if ican figure out any further optimisations

I can definitely get this running right, but might need to ask a bit more at some point…

Ok, blueprints and event dispatchers is the way ( or one anyway ). I can rotate a whole ship side of cannons towards a target point without any frame hit whatsoever:

aim

There is an actor BP in the scene, which tells the cannons where to aim. Right now, I’m just aiming at the origin:

and the blueprint picks that up like this:

I’ve just realized, this only lets you point all of them in one direction. But it demonstrates something… :smiley:

looks bussin many thanks :ok_hand:
ill come back tmrw once ive properly implemented this

Ok, a simple get actors is fine

I’m pointing them at random locations ( in a box ) here. And in the BP

random

Tell me if you see anything useful, and we can work out how to fit it with your regime.

1 Like