Bouncing Off Edges of Screen

I’m making a 2D game where I’d like the pawn to bounce in the opposite direction when it hits the edge of the screen.

The camera is fixed so I know the visible range. I currently have it working but the blueprint is large and feels messy. Below is the first 1/2 of the blueprint (I have two more similar cases for the Z values).

Is there a better/cleaner way to do what I’m doing here? I am new to Unreal Engine. Thanks!

If your left and right values are the same magnitude, just inverse (1024 and -1024) you can check to see if the absolute value of the X location is 1024, then flip the velocity accordingly. The same can be done for the Z values. It doesn’t clean up too much, but it will remove the second ‘Branch’ node from each check. You could also split the X and Z checks into separate functions if you wanted to clean it up a bit (a Bounce X and Bounce Z function for example), but overall it doesn’t seem like too messy of a blueprint

Thanks, yah that would clean it up a bit.

The main thing is t wanted to make sure I wasn’t doing anything dumb / there wasn’t a better/alternative/smarter way to be doing this. Seems OK so far, but if anyone else thinks of something better let me know :]