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

#1 2012-04-09 12:26:22

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Detection with guards.

I'm making a game with detection. The guards move around randomly until they detect you.

It works, except that the guard bypasses ALL the walls, and gets to you within .5 seconds; he basically blazes across the screen.

I need help. I'll show you the script I'm using for detection:

http://img4.imageshack.us/img4/4291/detectionacgame2.png
http://img854.imageshack.us/img854/9722/detectionacgame.png

Yes, I know, it's an AC game.  wink  I don't plan to sell it nor share it, I'm doing it for a class.

Offline

 

#2 2012-04-09 12:34:16

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Detection with guards.

aegisrunestone wrote:

I'm making a game with detection. The guards move around randomly until they detect you.

It works, except that the guard bypasses ALL the walls, and gets to you within .5 seconds; he basically blazes across the screen.

I need help. I'll show you the script I'm using for detection:

http://img4.imageshack.us/img4/4291/detectionacgame2.png
http://img854.imageshack.us/img854/9722/detectionacgame.png

Yes, I know, it's an AC game.  wink  I don't plan to sell it nor share it, I'm doing it for a class.

He's probably blazing across the screen because it keeps sending and receiving [detected] and so the "detected" script never has time to run all the way through, it just keeps getting reset.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2012-04-09 15:14:20

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

So, what would your recommendation be?

Offline

 

#4 2012-04-09 16:04:54

P110
Scratcher
Registered: 2011-04-12
Posts: 500+

Re: Detection with guards.

I would suggest,

forever
  if <(distance to [Ezio v]) < [200]>
  broadcast [detected v]
  end
end
Is that ok?

Also on the chaser

when I recieve [detected v]
forever
  if <touching [wall v]>
    turn (90) degrees
    move (5) steps
  else
    Point towards [Ezio v]
    Move (5) steps
  end
end
Hope this helps if this isn't what your looking for tell me and I'll alter the code.

P.S.It's better to use sprite sensing, rather than colour

Last edited by P110 (2012-04-09 16:06:51)


Me live on 2.0 now  sad

Offline

 

#5 2012-04-09 16:32:36

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

I think I am using sprite sensing.

Anyway, that stops him from moving through the wall, but if he's next to it, he'll bounce around really fast and never get to Ezio.

And if he's away from a wall, he'll still blaze toward Ezio once he's detected him, giving you no time to hide.

Offline

 

#6 2012-04-09 18:31:37

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

Okay, one thing I decided to do with being Hidden and Detected was to use variables since I don't think you can turn off a broadcast. I might have to make a variable for "BeginPatrol," too.

when i receive [BeginPatrol]
forever if <(distance to [Ezio v]) < [200]>
if <(Hidden) = [0]>
say [!] for [2] secs
set <[Detected v] to (1)> //Detected is a variable
else
say [?] for [2] secs
set <[Detected v] to (0)>
That's the first detection script, here's the one that's below it.

when i receive [BeginPatrol]
if <(Detected) = [1]>
forever
if <touching (MazeMainLvl v) ?>
turn cw (90) degrees
move [5] steps
wait [0.5] secs
else
point towards [Ezio v]
move [5] steps
wait [0.5] secs
end
end
end
if <(Detected) = [0]>
stop script
This doesn't seem to work very well. The guard seems to behave as if he's detected you already, though the "!" doesn't appear over him. Also, when chasing Ezio, the guard can sometimes go through the wall.

Can anyone help me with this? Please?

Offline

 

#7 2012-04-09 21:27:46

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

I'm sorry to triple post, but please, I need help!

Offline

 

#8 2012-04-09 22:17:54

SOScratch
Scratcher
Registered: 2010-02-01
Posts: 100+

Re: Detection with guards.

On your broadcast variables, I suggest that instead of using the normal:

broadcast [whatever you're broadcasting v]
I suggest you use a:

broadcast [whatever you're broadcasting v] and wait
Now instead of the script continuing to repeat itself, the script broadcasting will now wait until the detected script is done and so doesn't continue to repeat itself.

So it will look like this:

forever
if < (distance to [Ezio v] ) < [200] >
broadcast [Detected v] and wait
when I receive [Detected v]
forever
point towards [Ezio v]
move (5) steps
say [!] for (2) secs
end
Now this should work.

Last edited by SOScratch (2012-04-09 22:18:59)


-SOScratch
Scratch On!

Offline

 

#9 2012-04-10 09:52:23

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

Okay, but what if I want it to make sure so that when Ezio is out of range or hiding in a haystack that it stops the broadcast: "Detected," and makes the guard go back to "BeginPatrol"?

Thanks to everyone who's responded so far, BTW.  smile

Offline

 

#10 2012-04-10 11:44:41

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

Update! (I wish there was an edit button)

Here's my guard script: http://img441.imageshack.us/img441/2816/acguard1.gif

Before, for some odd reason, he wouldn't rush me.

Now, I added a sprite that is an "!" that appears on him. Now, he blazes toward Ezio, and well, I die.

Offline

 

#11 2012-04-10 13:40:14

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

http://img593.imageshack.us/img593/2816/acguard1.gif

This is the new guard script.

I made it so that the guard doesn't rush you. But I'm trying to get him to go to between two way points. It doesn't work. Sometimes, he goes up instead of going down. And then when he hits the second waypoint, he doesn't go back up.

I'm sorry for all the double/triple posting, but I really need help! This is for a class, and I need to finish it to turn it in.

Offline

 

#12 2012-04-10 20:55:11

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Detection with guards.

Simply start with your, when green flag is clicked script. Put a forever block down, and then an if block in the forever block. in this if block it should say, if distance to Ezio is greater than, 200, for example, and then in the block say, glide to x-wherever y-wherever. Wherever your first way point is. then put in another if block. This one should read, if distance to Ezio is less than 200, and then move towards him, however far you want him to move. After this, there should be a copy of the first if block, with the coordinates of the way point being the only thing changed. Then add a replica of the second if block. How far the guard moves, for how long, is up to you. You also said you had walls, you will have to add separate scripts to keep him from going through them. Other than that, and changing costumes for walking and running, that should work. The only downside is that the guard only notices Ezio if he is at a way point. But he will go back to his post if Ezio gets to far away. To add anther way point to his patrol, simply copy the first and second if blocks again, only changing the glide coordinates to your new point. I hope this helps you finish you project


Why are the secret organizations getting all the attention?  mad

Offline

 

#13 2012-04-10 21:26:23

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

Okay, thanks. Though, when you press the Green Flag, you are taken to the start screen, where you have to press the start button to start the game. But that shouldn't make a difference, right?

Offline

 

#14 2012-04-11 08:58:06

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Detection with guards.

It depends on what part of the game you want this guard in. You could have him wait a certain amount of time before starting his rounds, or you could put down a, when I recieve script instead of the flag. If you do that, you need to make sure something else broadcasts this message at the appropriate time.


Why are the secret organizations getting all the attention?  mad

Offline

 

#15 2012-04-11 09:04:25

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Detection with guards.

aegisrunestone wrote:

Okay, but what if I want it to make sure so that when Ezio is out of range or hiding in a haystack that it stops the broadcast: "Detected," and makes the guard go back to "BeginPatrol"?

Thanks to everyone who's responded so far, BTW.  smile

I haven't read this entire thread, but just modify SOScratch's script a little, so it becomes this:

forever
if < (distance to [Ezio v] ) < [200] >
broadcast [Detected v] and wait
end
when I receive [Detected v]
repeat until < not <(distance to [Ezio  v]) < [200]>>
point towards [Ezio v]
move (5) steps
say [!] for (2) secs
end
broadcast [BeginPatrol]

Last edited by Greenatic (2012-04-11 09:04:41)

Offline

 

#16 2012-04-11 10:51:57

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: Detection with guards.

I don't really know what kind of game you are creating, but it could be interesting to make the guard(s) walk along a path instead of continuously moving towards the player.

when green flag clicked
forever
  glide (3) secs to x: (-150) y: (-150)
  glide (3) secs to x: (150) y: (-150)
  glide (3) secs to x: (150) y: (150)
  glide (3) secs to x: (-150) y: (150)
end

when green flag clicked
forever
if <(distance to [player v]) < (100)>
  broadcast [caught v] and wait
end
end


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#17 2012-04-11 19:53:01

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

sonicfan12p wrote:

Simply start with your, when green flag is clicked script. Put a forever block down, and then an if block in the forever block. in this if block it should say, if distance to Ezio is greater than, 200, for example, and then in the block say, glide to x-wherever y-wherever. Wherever your first way point is. then put in another if block. This one should read, if distance to Ezio is less than 200, and then move towards him, however far you want him to move. After this, there should be a copy of the first if block, with the coordinates of the way point being the only thing changed. Then add a replica of the second if block. How far the guard moves, for how long, is up to you. You also said you had walls, you will have to add separate scripts to keep him from going through them. Other than that, and changing costumes for walking and running, that should work. The only downside is that the guard only notices Ezio if he is at a way point. But he will go back to his post if Ezio gets to far away. To add anther way point to his patrol, simply copy the first and second if blocks again, only changing the glide coordinates to your new point. I hope this helps you finish you project

Okay, it's working, except the guard is gliding through the level walls. How do I fix that?

Thanks so much, BTW.

Offline

 

#18 2012-04-12 09:49:38

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Detection with guards.

If he's gliding through walls to get to a waypoint, the you should have more than two waypoints to make sure he doesn't hit walls on his way to the next one. You should also make a separate script that says, forever, if guard is touching(color of wall) if the wall is part of the stage background, or if the wall is a separate sprite(which usualy works best)then change, if touching color to, if touching wall, or whatever the sprites name is. In the if block you should then put something like, move - 10 steps, to get him off the wall. That should solve the problem.  smile


Why are the secret organizations getting all the attention?  mad

Offline

 

#19 2012-04-12 12:18:45

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

A separate script? So, something like...

when I receive [BeginPatrol]
forever
if touching (Wall)
turn cw (90) degrees
move (-10) steps
Like that?

Offline

 

#20 2012-04-12 18:07:48

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

Kay. It's not working, the guard is still floating through the maze walls.  hmm

The maze walls are all one sprite, BTW.

Offline

 

#21 2012-04-12 18:20:44

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

Another thing. I do want to use variables because Ezio can hide in Haystacks, making detection worthless.

http://img832.imageshack.us/img832/8546/acgaurd12.gif
http://img268.imageshack.us/img268/3007/haystackscript.gif

How do I work with this? Or I am being too complex?

Offline

 

#22 2012-04-12 20:35:23

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Detection with guards.

It is a bit complex. I don't really have an answer right off the bat, but I'll try and look into it. It might take a bit, because I'm in the middle of making the next level of Tankssad  When is this supposed to be due? I'll try and figure out this problem before then.


Why are the secret organizations getting all the attention?  mad

Offline

 

#23 2012-04-12 20:39:15

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Detection with guards.

One more thing, to figure this out, I'm going to try and make one of the levels. If you could tell me the objective of a level, and if Ezio has any special abilities, that would help a lot.


Why are the secret organizations getting all the attention?  mad

Offline

 

#24 2012-04-12 21:37:32

aegisrunestone
New Scratcher
Registered: 2012-04-08
Posts: 34

Re: Detection with guards.

The point is to get the Scroll of Altair. Ezio has lost his Hidden Blades, so he can't kill any guards. He has to avoid being detected. There are three guards in the level, and three haystacks. If Ezio needs to, he can use a haystack to avoid getting detection. If the guards touch him, he loses a Health Square. If he loses all his Health Squares, he dies (You only get 2 Health Squares). If he gets the scroll, he wins.

The game is overhead view. And the game is due Tuesday.

Thanks.  smile

Offline

 

#25 2012-04-12 21:40:53

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Detection with guards.

Okay!  smile  I'll get started on it as soon as possible. When I'm done, I'll post a link on here, and you can download it and look.


Why are the secret organizations getting all the attention?  mad

Offline

 

Board footer