Hey @FADEDTHANAHOE!
You can check out this post of mine on this exact same topic
Hereās another version of the same thing but in this one I added line trace to make it change direction when itās about to hit an obstacle.
(This was an older screenshot of mine so I canāt edit it now. Thereās one thing you might wanna change. I reset the Do Once node after it executes which is pretty pointless. It should be reset after the False node of my Branch. You wonāt encounter a much of an issue if you leave it as it is, it just causes a little stutter when itās changing the direction. But you can easily fix that the way I explained here.)
And hereās the result of it
As for the steps:
Right click on an empty space in your Content Browser and hit the Blueprint Class option under the Create Basic Asset section. On the menu named āPick Parent Classā that pops up, select Pawn under the Common section. Inside our new pawn class blueprint, navigate to the Components section on the top left and hit the Add button with a green plus icon on it. Type in āfloating pawn movementā and add the Floating Pawn Movement component. Then implement the blueprint code inside the Event Graph.
One more thing, you see inside my Line Trace by Channel node, the trace channel is set to āCustomā. Thatās a custom trace channel that I named āCustomā. So you can also create a custom trace channel (optional) to determine which objects our pawn will consider as obstacles. To do that, navigate to Edit > Project Settings and type in ātrace channelā into the search bar. Youāll see the Trace Channels section being filtered up under Engine - Collision. Hit the New Trace Channel button and name it whatever you want. But itāll ask you what itās default response is gonna be. If you set the default to block, youāll need to adjust the collision responses of the objects you want to be ignored by setting them to ignore, and if you set the default to ignore, youāll need to adjust the collision responses of the objects you want to be considered as obstacles by setting them to block.
Also in addition to already visible objects, you can place invisible walls in your level to act as borders, for example where the water ends or the borders of your map etc.
For clarity, hereās what this blueprint code does:
- Our lil guy changes direction every 3 seconds
- When itās about to hit an obstacle, it changes direction at least 45 degrees on each direction
- After it changes direction, the timer resets
- The pawn can also be confined inside pre-determined borders
Hope this helps!