Hi everyone, I have an issue with severe performance loss in the way I’m aligning my vehicles to the floor. What I’m currently doing is a timer every .1 of a second, then a line trace from my actor’s location. If that raycast is successful I make a rotation from the hit location and I do an RInterpTo the new rotation.
Now this works, but as my game has 200+ units on the screen a time that are each doing this I’m having a huge loss in performance. About 15fps with an i7 12700k, and a 4070ti when doing this terrain alligning. So does anyone have any ideas on how I can make this way more efficient?
Some extra info, I am using the built-in navigation and movement system so I’m not sure if there is a way of doing it through here.
The actors never stop moving, as it’s a tower defense game they go from point A to point B so through the whole life cycle they are moving. But no I do not clear the timer as they’re always needing to align to the floor maps are sloped up/down basically very little flat land.
You could try doing this inside of tick, hold the amount if time passed since the last time you corrrected the rotation and do it every time it goes over 0.1s. Should be slightly lighter than a timer.
Also, you mentioned you are using built in movement system. Do you mean character movement component(CMC) ?
If yes, CMC does similar rotation correction(around Z axis) multiple times every frame and you are basically overriding that which means lots of cpu time is going to waste. I would say inheriting CMC and making your own custom movement mode and doing this there would be a lot cheaper computationally…
Alright, I can try it on Tick and see how that goes. And yes the character movement component, I have my units using this to move instead of my own movement system, as I previously created my own and switched over to the built-in one as it was significantly more efficient than what I wrote. From what I noticed it only touches the horizontal rotation of a unit whereas I also need to also vertical rotation to match the angle of the slope, as it doesn’t seem to do this. Unless I’m missing some setting or something of that sort for the CMC?
Yes it only changes the capsule rotation on Z axis (horizontal) but it also does lots of other stuff including ground checks.
By custom movement I didn’t mean writing your own system from the scratch. You basically create a new component inherting CMC. Then create a custom movement mode, copy and paste CMC default walking physics, remove whatever you don’t need, add X and Y rotation fixes, maybe even remove sub stepping (this might lower the movement quality though but improves performance considerably) and use that mode instead of the normal walking mode of CMC. Should result in way less function call overhead and also less computation. Takes considerably longer time to implement though.
You can check this play list for a very useful series on how to make custom movement from CMC: