# flying bird random fly

**URL:** <https://forums.unrealengine.com/t/flying-bird-random-fly/1875295>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, Blueprint, question\
**Created:** [May 27, 2024, 1:11pm UTC](https://forums.unrealengine.com/t/flying-bird-random-fly/1875295 "2024-05-27T13:11:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Td1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/td1/32/894132_2.png) [@Td1](https://forums.unrealengine.com/u/Td1)\
**Post date:** [May 27, 2024, 1:11pm UTC](https://forums.unrealengine.com/t/flying-bird-random-fly/1875295/1 "2024-05-27T13:11:42Z")

</div>

i want to make an ai bird that fly randomly . tried to do it with ai move to but failed , any help.

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [May 27, 2024, 1:54pm UTC](https://forums.unrealengine.com/t/flying-bird-random-fly/1875295/2 "2024-05-27T13:54:54Z")

</div>

try to use “move to location” node ,it allows you to move the birds in the air,and doesn’t need a navmesh.

And use “random unit vactor” to generate a random direction,then use that direction to fire a line trace(also a random length in a wanted range).and then if it hit something means that the the location is on the ground,we need to regenerate new location again. only when the line trace has hit nothing,we can use the line trace’s end location for the target location.

---

<div class="post-metadata">

**Author:** ![Td1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/td1/32/894132_2.png) [@Td1](https://forums.unrealengine.com/u/Td1)\
**Post date:** [May 29, 2024, 4:11pm UTC](https://forums.unrealengine.com/t/flying-bird-random-fly/1875295/3 "2024-05-29T16:11:03Z")

</div>

i think in my map its impossible for it to not hit anything with the line trace , because my map is have a roof but its very high . i don’t know mush about line trace if it keep going till it hit something even if its far then it wont work but i will give it a try.

> [@baobao4435](#):
>
> try to use “move to location” node ,it allows you to move the birds in the air,and doesn’t need a navmesh.

"move to location "So i use the move to location or actor node.

> [@baobao4435](#):
>
> And use “random unit vactor” to generate a random direction,then use that direction to fire a line trace(also a random length in a wanted range)

so i use a random unit vector in a line trace by channel in the start of the line trace.  
so what to put in the “end” of the line trace so it doesn’t hit the roof?

> [@baobao4435](#):
>
> .and then if it hit something means that the the location is on the ground,we need to regenerate new location again. only when the line trace has hit nothing,

sol i break hit the result , get a branch connect it to the blocking hit if it was true i repeat, if false i take the trace end set it to variable , use it as as the "move to location or actor " node goal

is this what i need to do?

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [May 29, 2024, 7:08pm UTC](https://forums.unrealengine.com/t/flying-bird-random-fly/1875295/4 "2024-05-29T19:08:48Z")

</div>

I made an quick example for you to reference ,

First the bird should be a pawn,create it with a pawn and then add a “floating movement component ” to it.  
at the bird’s begin play;

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/f/d/6fd9df7b1a0accf722682846aad20d5983d7bc16.png)

the move event:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/5/e/b5e6c189876f6b3fb3801f76779a26c4a40f264f.png)

the custom function:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/4/3/343de61514b1ddf655483f0a8a46f50464c35fb8.png)

---

<div class="post-metadata">

**Author:** ![Td1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/td1/32/894132_2.png) [@Td1](https://forums.unrealengine.com/u/Td1)\
**Post date:** [May 30, 2024, 10:01am UTC](https://forums.unrealengine.com/t/flying-bird-random-fly/1875295/5 "2024-05-30T10:01:37Z")

</div>

thanks,

also i really like the comments you did in the bp it explains alot. thanks

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [May 31, 2024, 3:45pm UTC](https://forums.unrealengine.com/t/flying-bird-random-fly/1875295/6 "2024-05-31T15:45:38Z")

</div>

I realize that the custom function has a critical issue.if the bird accidentally goes to a narrow place.it won’t able to find a location.the function will run infinitely.might crash the game.

here are some modified BPs.  
begin play

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/c/a/dcade82e1d4bea97ce46f8caf6c7d62447f843a1.jpeg)

In the function

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/6/4/b641a6f669ed98fb961d5bdee977344831d97ed9.jpeg)

move event

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/6/736025667217aa9c40e0b90618a9ff08c7ded1b3.jpeg)

---

<div class="post-metadata">

**Author:** ![Td1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/td1/32/894132_2.png) [@Td1](https://forums.unrealengine.com/u/Td1)\
**Post date:** [June 8, 2024, 6:23pm UTC](https://forums.unrealengine.com/t/flying-bird-random-fly/1875295/7 "2024-06-08T18:23:40Z")

</div>

thanks, I just saw that. I really appreciate that.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 8, 2024, 6:24pm UTC](https://forums.unrealengine.com/t/flying-bird-random-fly/1875295/8 "2024-07-08T18:24:02Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
