Avoid things (water)

Hannah+
Posts
1
Karma
1
Hannah+ posted this 26 May 2016

Hi, 

 

Can anyone tell me how I make Kodu avoid things as in my students games characters just keep going in the water! We've tried "when hear ocean Do move away" but this doesn't work?

 

Thanks, 

Hannah 

0
Stephen
Posts
568
Karma
588
Admin
Stephen posted this 26 May 2016

Hi Hannah,

 

There is no easy way to have character not run into the water.  Probably your best bet is to use paths to guide the character around the water.

 

Experimenting a bit I was able to get a Cycle to avoid the water when hunting for apples.  The way the kode works is to detect when the character hits water and have it turn around and move back from the water and try again.  This works best with round lakes.  With a winding river you'll probably stay stuck.  The kode looks like this:

 

Page 1 -- If I run into water while moving toward an apple, switch to page 2.

WHEN See Apple DO Move Toward

WHEN OnWater DO Switch Page2

 

Page2 -- Immediately stop moving, switch to page 3.

WHEN DO Move Freeze

WHEN DO Switch Page3

 

Page 3 -- Spin in place 1-2 seconds.  For the Cycle this gets him mostly turned around.  Then switchto page 4.

WHEN DO Turn Right

WHEN TImer 1Second Random 1Second DO Switch Page4

 

Page4 -- Move straight ahead for a couple of seconds and then switch back to page 1.

WHEN Timer 2Seconds DO Switch Page1

WHEN DO Move Forward

 

Note that all the timer values are set for the Cycle's normal speed.  If you've changed the speed or are using a different character you might have to tune the values.

 

Hope this gives you some ideas.

0