Limiting ActorLocation's "X" value

Hello reader,

My question is simple yet it’s got me wondering…I’m trying to limit my character’s ActorLocation’s X movement by checking it each tick. If it’s larger or smaller than my desired value I set it back to my desired min/max.

I’m talking about a classical fighting game where I’m setting the “walls”. I don’t want to use actual walls as it won’t let my character go to exactly my desired min/max… Feels like a cheap way out, which doesn’t work correctly anyway.

So I’m doing the tick-trick…

Am I being paranoid or this actually real bad practice? I feel like I might be tearing through CPU inefficiently and I would really want to avoid that.

I get that feeling especially because I’d be constantly getting and setting Y and Z for no reason at all. Since it’s a fighting game I’d be doing it twice, too.

Thank you for your time!

Eyo,

The character normal movement component does their movement calculations in tick so you should probably not be scared of using tick.

The answer will be different depending on your current setup and how you move your character. But assuming you use the CharacterMovementComponent I
personally think that it is bad practice to have more than one place where the player movements get calculated. (Movementcomponent + SetActorLocation)

I would probably use a Blocking volume if I need any other functionalities I’d make it to a BP and have variables where I can get the “perfect” Max/Min Locations.

Hi Celldeining. Thank you so much for your answer. I have already solved it by the way. But yes what I did is actually what you are suggesting here so I can confirm it works fine. I had the blocking volumes first, and they were annoying cause I could have perfect control over the exact outer limits of character positioning. But… after a few tries and a few extra calculations, the blocking volumes are just fine !

Good to hear that it worked out fine! :slight_smile:

I think a good rule of thumb is to always try to use Unreals already proven out systems first.

Agreed, however good of a developer you may be, I think one very, very rarely succeeds in optimizing against a specialist.