How do I make a sprite roam randomly through layout?

Get help using Construct 2

Post » Thu Mar 27, 2014 8:19 am

[color=#804080][color=#800040][color=#800040][color=#40FF80][color=#800000]Hi, I want to make an NPC sprite moves randomly through the layout, something like fish frenzy when there are lots of fish moving around but when you try to attack them they flee. Thanks for reading my topic :)[/color][/color][/color][/color][/color]
B
4
Posts: 24
Reputation: 250

Post » Thu Mar 27, 2014 10:58 am

Give Fish behaviour Bullet.
Make 4 sprites as long lines, call it LeftBorder, TopBorder etc. Have it on the edge of your layout. Have it set INVISIBLE. These will form the boundaries for your fish.

Have a Collision check.

Fish Collision with TopBorder = set Fish angle random(30, 150). Whenever fish touch top border, it will swim downwards in a random manner, ie. it will change direction.

Do the same for collisions with other borders, just set the angle to be in the opposite direction with random.

Another thing you can do to make it even more random roaming:

Every Random(5,10) Seconds = Set fish angle random(0,360).

Try that and your little fishies will be swimming all around withing your layout.

If u want them to flee in the opposing direction when attack, just set their angle on an attack trigger and increase their bullet speed for a few seconds before returning it to normal speed.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,614

Post » Thu Mar 27, 2014 12:57 pm

Thanks a lot ..this was really helpful :)
B
4
Posts: 24
Reputation: 250

Post » Thu Mar 27, 2014 2:22 pm

I once made a Fly example about the same way..

Image
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Mar 27, 2014 7:10 pm

Thanks Littlestain......I will try this method too!
B
4
Posts: 24
Reputation: 250

Post » Mon Mar 31, 2014 2:19 am

@brandonmcfee you can try this also.
https://www.scirra.com/forum/download/file.php?id=750
Please Support Ocean Explorer.
http://igg.me/p/735007/x/6915815
B
14
S
4
G
3
Posts: 125
Reputation: 2,645


Return to How do I....?

Who is online

Users browsing this forum: alextro, tarek2, wenwen11212016 and 7 guests