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

#1 2011-05-06 20:52:25

HighdownY8
Scratcher
Registered: 2011-05-06
Posts: 1

Advanced maze collision detection question

I've made a little 2 player bomberman style game based on the SNES classic but I am still not happy with how my scripts are deal collision detection.

As it stand I have placed a 1 pixel line in a dark colour around all of the objects in the maze and used touch sensing. While this works to a degree it is glitchy (characters getting stuck etc).

Could anyone point me towards some more advanced collision handling scripts please, I've tried searching but since maze games are where most people start I'm sure you can guess what happens.

Thanks!

Offline

 

#2 2011-05-06 21:14:58

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

Re: Advanced maze collision detection question

Hm...well, you can use a method like this:

If <up key pressed>
change y by 2
If color (upside color) touching (wall color)
Change y by -2

and so on and so forth.  This ensures that it will always move back if it's actually touching the wall but not to much as to offset it.  If you have a different type movement you're using, just post it and I'll make my own version and post it for you to check out.


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

Offline

 

#3 2011-05-07 09:13:13

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Advanced maze collision detection question

There are many ways on how to make collisions, the popular way has been said by AtomicBawm3.

Other ways that are a little smoother could be where the Main Sprite has a "sensor" dot where if < color [dot] is over [wall] > then it can't go in that direction:

Code:

[ When Flag Clicked ]
[ Forever ]
[] [ if < not < color [North Dot] over [Wall Color] > > and < key [Up Arrow] pressed? > ]
[] [] [ Change Y by [ 5 ] ]
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
[] [] [] [] []

So the colors could be: 'Ground' is White, 'Walls' are black, 'North Dot' sensor is blue. If Blue of Main Sprite is over Black, it disables going North.

The sensor dot will have to be some where ( about 5 pixels ) North of the Main Sprite ( these dots are part of the Sprite Costume ).

Just do the same ( with a different color ) for each direction.

Another way is through 'distance' but that would be pretty complicated.

Examples on collision detection:
s_federici: http://scratch.mit.edu/projects/s_federici/155861
MasterOfMac: http://scratch.mit.edu/projects/MasterOfMac/113130

Last edited by Magnie (2011-05-07 09:13:50)

Offline

 

#4 2011-05-07 09:33:59

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Advanced maze collision detection question

Here's a popular method:
http://i51.tinypic.com/mbiooy.gif


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

Board footer