This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-04-19 22:46:44

Completen00b
Scratcher
Registered: 2009-04-19
Posts: 3

Need help making my enemy work properly

Hi I'm not sure if this is the right place to ask this.(If there is a better place to ask it let me know)
Anyway I'm making my own version of wii plays tanks game and I'm having difficulties with the Enemy tanks and how to get them to move towards the player and fire whilst evading walls and objects
All i can manage is for him to point at the player and move towards it which results in him running into a wall, firing and killing himself:P.
Any ideas and thoughts would be appreciated.

Offline

 

#2 2009-04-19 23:32:18

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Need help making my enemy work properly

It depends on the script you use for the tank, really. But I came up with this, if you find it useful:

http://img27.imageshack.us/img27/4476/scripttank.gif

Last edited by technoguyx (2009-04-19 23:32:29)


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#3 2009-04-20 01:28:37

Completen00b
Scratcher
Registered: 2009-04-19
Posts: 3

Re: Need help making my enemy work properly

Thanks for that it's quite helpful didn't think of making it stop a certain distance away or take a random time to fire (I like that idea).
Any idea on how to make it evade walls? and only shoot when there is line of sight so it doesn't try to shoot you through a wall

Offline

 

#4 2009-04-20 08:00:26

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Need help making my enemy work properly

Completen00b wrote:

Thanks for that it's quite helpful didn't think of making it stop a certain distance away or take a random time to fire (I like that idea).
Any idea on how to make it evade walls? and only shoot when there is line of sight so it doesn't try to shoot you through a wall

You could use another, hidden sprite. And then, use the "color [] touching []?" block.

Let's say you make the sprite some sort of hidden laser, measuring about 50 pixels (since that's the distance to shoot), and you make it red. Then you'd use this on it:

http://img23.imageshack.us/img23/6473/scripttank2.gif

But now, it should move away when it detects a wall. That sounds hard to me  sad  Maybe a variable could help, only when that variable is set to 1, run the "following player" script. When it's set to 0, the AI turns away.


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#5 2009-04-21 22:03:25

Completen00b
Scratcher
Registered: 2009-04-19
Posts: 3

Re: Need help making my enemy work properly

That idea works really well thanks for that I have 1 more problem tho,
Never mind i figured it out  tongue

Last edited by Completen00b (2009-04-21 22:05:47)

Offline

 

Board footer