0
\$\begingroup\$

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.

Many thanks in advance :)

 X

\$\endgroup\$
1
\$\begingroup\$

A better way of doing this may well be to use a clamp on your character's movement component to limit where they can go in X.

https://docs.unrealengine.com/en-US/BlueprintAPI/Math/Float/Clamp_float/index.html

This will remove the need to use the Tick function if that's your end plan.

-

Edit based on comments: As you're using InputAxis and AddMovementInput, after the InputAxis you can use a couple of branches to check the Actor Location and the value of the InputAxis. If calling movement will move your character outside the pre-defined range of X, don't execute movement.

\$\endgroup\$
8
  • \$\begingroup\$ This is definitely the first thing you should try. CPU's are more efficient than you think, but you're doing the right thing by concerning yourself with time complexity. Alternatively, you could use Unreal's collision system and set up colliders in your level to constrain your character. \$\endgroup\$ – Natalo77 Mar 12 '20 at 9:31
  • \$\begingroup\$ @Stephen, thank you. I'm familiar with clamp, however I'm making use of InputAxis for my movement. Can I clamp that? I tried to fit it somewhere in that structure of blueprint but I did not find "the way". @ Natalo, thank you also. As far as the collision system and colliders, I've noticed it does not keep things "clean". I mean the characters tremble slightly when you try to force moving anyfurther with your input buttons. That's why I removed my fake invisible "walls" \$\endgroup\$ – Seyia X Mar 12 '20 at 10:10
  • \$\begingroup\$ @SeyiaX If you're using a function for movement which is setting actor location, you can put the clamp in this. \$\endgroup\$ – Stephen Mar 12 '20 at 10:39
  • \$\begingroup\$ @Stephen, yes but what's blocking me is that InputAxis node is being attached to AddMovementInput of my character. Is there a way that InputAxisNode can be used with SetActorLocation? Sorry for the newbie questions.. But that would really solve it then :) \$\endgroup\$ – Seyia X Mar 12 '20 at 13:10
  • \$\begingroup\$ @SeyiaX Try increasing the scale of your world. There's a possibility that the jittering in the collider system can come from minor floating point errors if your world scale is too small. This is a very minor possibility, but it's worth a try. \$\endgroup\$ – Natalo77 Mar 13 '20 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.