Looking for cleaner blueprint code ideas - restricting actors movement based on relative location


I am moving an actor based on its relative location from another actor that it is attached to.

I want to restrict movement to not go outside a bounds. For instance, we should not be able to move more than 50cm’s away from the parent in any direction.

The only way I can think to do this is very messy. Something like this:

Get relative location X → if above upper bounds & incoming input is positive, do nothing, only allow negative input

and vice versa for the lower X bounds. And then same thing for upper and lower Y bounds.

This is certainly going to work, but I figured there might be some math trick that might make for cleaner code. Anybody have an idea about something like that?

Assortment of Max / Min / Clamp nodes plus Get-Distance-To / Compare-Float maybe…

1 Like

hey @AntiGravity , thanks you gave me the right idea.

I was hung up because I was using the Add relative location node.

But this is simple and it seems to work:

1 Like

if(DistanceFromParent / MaxDistance) < 1)

DistanceFromParent / MaxDistance will give you a number between 0 - 1 as a ratio of the distance remaining to MaxDistance (e.g. 5/50 = .1 and 50/50 = 1) (10% / 100%)

Once you’re ratio is 1 you’ve traveled your maximum distance.