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

#26 2010-08-15 14:30:16

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Does anyone know of a way to do collision sensing without hitests?

Harakou wrote:

shadow_7283 wrote:

RHY can do it.  big_smile

Yeah, but RHY is well, RHY.

shadow_7283 wrote:

I can't stand color sensing. Anyway, to collide without any annoying color sensing or extra sprites or extra costumes, you just use this script on top of whatever movement script you have (preferably with velocity)

    When Green Flag Clicked
    Forever
    (velocity stuff)

    change x by (x velocity)
    if touching platforms
    change x by 0 - (x velocity)
    set x velocity to 0

    And then you can do the y stuff

    change y by (y velocity)
    if touching platforms
    set y velocity to 0

    And after that if you have gravity then you will be brought back down.

This is how Rhy did it, but I don't think that this is a good method and I will show you why.


[c][ ][ ][ ][ ][w]

Pretend that c is the character and w is the wall.

[ ][ ][ ][ ][c][w]

Now as the above diagram illustrates, assume that the character is next to the wall and the xvelocity is set to 1.

Now assume that this script activates:

    change x by (x velocity)
    if touching platforms
    change x by 0 - (x velocity)
    set x velocity to 0

The character will move into the wall's space and then move in the opposite direction by 1 unit because of the change x by 0 - (x velocity) script.

Now assume that the xvelocity had been 2 instead of 1.

With the character starting at this position
[ ][ ][ ][ ][c][w]

Moving to the wall with xvelocity of 2 would make the player end up at this position

[ ][ ][ ][c][ ][w]

We do not want the character to be this far away from the wall.

Rhy was make to make this look good in his platformer template because he used a small value for movement, which according to what you just read, produces the desired effect.


The absolute best way to do things for something like a pacman game (in which case it is essential) is to set up a tile grid and check for collisions based on the values in the lists and the player's current tile and movement.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#27 2010-08-15 15:24:34

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Does anyone know of a way to do collision sensing without hitests?

Yeah, I suppose. I didn't realize that steppenwulf was asking for a script for Pacman (I didn't read the posts properly). The best method for Pacman is by far tile sensing (just use a list!) but for platformers, I like RHY's script. Even if it makes you go back a bit, you can easily adapt it to make it look like a normal "bounce-off-solid-objects" type thing.

It creates a pretty nice effect in projects like this: http://scratch.mit.edu/projects/shadow_7283/1067907

Last edited by shadow_7283 (2010-08-15 15:26:17)

Offline

 

Board footer