Flight Path
Blitz3D Forums/Blitz3D Beginners Area/Flight Path
| ||
Hi All, Im making a wild life demo and would like to have birds fly through the world randomly. I could just randomly launch a bird acroos the screen every now and then but i would like to get it more life like, so they change direction and hight and speed, but i have no idea how to start with this, Any Ideas... Thanks |
| ||
There's a demo that comes with Blitz which demonstrates something like this - I think its the Bird Demo by Adam Gore. |
| ||
In short, 1) create multiple birds with random x,y,z locations 2) each frame, adjust each birds x and/or y and/or z (depending on how you want them to fly) by a given amount (deltax, deltay, deltaz) 3) Have a counter for how long they should fly in that direction that counts down every game loop 4) when the counter=0, reset the counter and change the deltax and/or deltay and/or deltaz values. The bird will now fly in a different direction. Don't forget to reset your counter. In code :- type bird field x field deltax field y field deltay field z field deltaz field time_until_direction_change end type for createloop=0 to [number of birds you want] thisbird.bird = new bird thisbird\x = (random value) thisbird\y = (random value) etc. for the other fields. next Each game loop do something like for thisbird.bird = each bird thisbird\x=thisbird\x+thisbird\deltax (ie. each loop, add the "deltax" value to the current x value) thisbird\y=thisbird\y+thisbird\deltay thisbird\z=thisbird\z+thisbird\deltaz (the bird will now redraw at the new location) thisbird\time_until_direction_change=thisbird\time_until_direction_change-1 if thisbird\time_until_direction_change=0 then thisbird\time_until_direction_change = (a reset value) deltax = (new amount to change x by each loop) deltay = (new amount to change y by each loop) deltaz = (new amount to change z by each loop) end if |
| ||
Birds fly up and down gently, like on a wave, so use sin() to adjust the height (y) of the birds. |
| ||
thanks guys |