Jump to content
  • Advertisement
Sign in to follow this  
Ildun

Need help in prioritisation AI ( action script )

This topic is 3905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I still not familiar with action script, so I am not sure whether it is coding problem or logic problem. Currently I doing a prioritisation AI where my character ( movie clip name: tiger ) will eat the unit ( movie clip name: sheep ) which is nearest to it. The movie clip "sheep" is an icon which can be drag. When click on it, it will duplicate new movie clip instance and I can drag and drop it into the field I define. When the new sheep instance drop onto the field , the tiger will move toward it, however when I drag another sheep instance and put it relatively nearer to the tiger, the tiger will change target and move to it first. Here are my codes: tigerymvspd = 5; tigerxmvspd = 5; sheepnum = 0; D = 0; _root.onEnterFrame = function() { _root.sheep.onMouseDown = function() { _root.attachMovie( "sheep", "sheepy_"+sheepnum, ++D ); _root["sheepy_"+sheepnum].startDrag(true); } _root.onMouseUp = function() { _root["sheepy_"+sheepnum].stopDrag(); sheepnum += 1; } if( _root.tiger.hunger > 0 && sheepnum > 0 && _root.tiger._x + 20 < _root.field._x + 200 && _root.tiger._x - 20 > _root.field._x - 200 && _root.tiger._y + 20 < _root.field._y + 200 && _root.tiger._y - 20 > _root.field._y - 200 ) { //Prioritisation if( sheepnum > 0 ) { for( k = 1; k <= sheepnum+1; k++) { sheep[k] = _root["sheepy" + k] distance[k] = Math.sqrt( Math.pow( ( _root["sheepy_" + k]._x - _root.tiger._x ), 2 ) + Math.pow( ( _root["sheepy_" + k]._y - _root.tiger._y ), 2 ) ); } //bubble swap technique for( j = 0; j < sheepnum; j++ ) { for( k = 0; k < sheepnum; k++ ) { if( distance[k] > distance[k+1] ) { mindistance = distance[k] distance[k] = distance[k+1] distance[k+1] = mindistance mindistance = sheep[k]; sheep[k] = sheep[k+1]; sheep[k+1] = mindistance } } } return sheep[0]; } //Tiger Approach Prey if( _root.tiger._x < _root["sheepy_" + k]._x && pathfinding == 0 ) { _root.tiger._x += tigerxmvspd; } if( _root.tiger._y < _root["sheepy_" + k]._y && pathfinding == 0 ) { _root.tiger._y += tigerymvspd; } if( _root.tiger._x > _root["sheepy_" + k]._x && pathfinding == 0 ) { _root.tiger._x -= tigerxmvspd; } if( _root.tiger._y > _root["sheepy_" + k]._y && pathfinding == 0 ) { _root.tiger._y -= tigerymvspd; } } The result is, the tiger does not move at at =0= Can any one tell me what is the problem? I squeeze my brain for two week still cannot figure it by myself, so I hope someone can help me on this~~~

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!