Discuss Scratch

YeOldieEngland
New Scratcher
2 posts

Smart AI

Alright I'm making a game for a friend of mine who is joining the service soon and its going to star a 8/14 bit version of him. But my problem is that he moves and fires but I need a script that will have the AI target and shoot at him and try to take cover. Now this is a lot but this game is my going away gift for him and I'd like to have it ready before he ships out to boot camp. If anyone can help that would be great.

Just for recap.
they need to
Fire back at him
Move around and take cover

Note I intend to use the walking/kneeling/firing script of my friends sprite for the enemy's it just needs to be automated.
So if you think you have a script that would work for one of these needs just post it in the comments and I'll give it a try.

Thank you, -YeOldieEngland

Last edited by YeOldieEngland (July 2, 2013 06:12:06)

Zparx
Scratcher
500+ posts

Smart AI

Hmm, could you perhaps provide a link to said project? I'm usually pretty good with ai programming.

If you're looking for coding idea, here's one that may interest you:

If the ai moves back and forth already, you could set a variable to pick random 1 to 3. if the variable = 1, have it target him and fire, if it = 2, have the ai just move around, and if it = 3, have the ai take cover.
YeOldieEngland
New Scratcher
2 posts

Smart AI

Thanks that works in the script but know when they are meant to die they go to the death animation but then go right back to moving instead of staying dead, any idea on how to stop them from doing that? Also I have a little trouble with getting them to do the script so they will move but then take cover and also shot. But at least they can move with out me doing it.
ErnieParke
Scratcher
1000+ posts

Smart AI

YeOldieEngland wrote:

Thanks that works in the script but know when they are meant to die they go to the death animation but then go right back to moving instead of staying dead, any idea on how to stop them from doing that? Also I have a little trouble with getting them to do the script so they will move but then take cover and also shot. But at least they can move with out me doing it.
For your first problem, all you need to do is add in an if around all of your code, like this:

|when gf clicked
|forever
| if (alive?) then
| pick 1 to 3
| act…
| end
Blank Line
Do you get the idea? Of course, you'll have to replace (alive?) with it's equivalent in code, but that shouldn't be too hard. Or, at the end of your death animation, you could put [stop ], though it might not work, depending on how you coded everything. Still, it's worth a try.

As for your second question, the one about shooting&taking cover, that's possible as well. So in your script, when you know you want to shoot, you'll have to choose a new random number, 1 or 2. If it is 1, then you simple shoot. If it's 2, then you shoot and take cover. Simple, right? Also, as a more aggressive variation, you could try picking between 1&2 when you know you'll be taking cover. So, 1 = cover & shoot, and 2 = cover.

Finally, just to say, an AI is a piece of code that reacts to the player or it's environment, so what you working on right now isn't exactly an AI till you've added a bit more.

With regards,

ErnieParke

P.S. Good luck with your project! Hopefully your friend will like it a lot.

Powered by DjangoBB