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

#1 2009-10-29 17:28:20

67589jun
Scratcher
Registered: 2007-07-13
Posts: 1000+

Colliding Script

http://scratch.mit.edu/projects/67589jun/736900

This script can be used in any game where you want a sprite not to go through an object.

(scrollers,platformers, etc.)

Basically, it records where the X and Y of where a sprite is in a variable. Once the sprite touches the color of your choosing, it stops recording where your sprite was and sends it back to the last recorded position of when it wasn't touching the object. This makes it EXTREMELY easy to do what a large amount of scripts can do.

I got the idea from a user who made a project and said in the description that he used the old "Return to last position trick."  I was in the middle of class when I thought of this. Using JUST ONE SCRIPT, I can make sprites with collision to objects.

How to use: Replace the two color blocks with the color you want it to collide with, (Use the "AND" block to add more colors.) set the sensor blocks to the sprite the script is in, and WHAMMO! You are finished.

Please take a look at the script and tell me if there is any glitches.


http://i.imgur.com/I1DuR.png

Offline

 

#2 2009-10-29 20:57:38

FurryWolf
Scratcher
Registered: 2009-10-28
Posts: 5

Re: Colliding Script

Pretty cool.


http://neeut.files.wordpress.com/2010/05/ss_neut_05-19-10_16-15-53_jupiter.jpg?w=480&h=326
Wish you were here

Offline

 

#3 2009-10-29 21:00:36

dano2master
Scratcher
Registered: 2009-10-29
Posts: 4

Re: Colliding Script

nice, i downloaded it

Offline

 

#4 2009-10-30 05:20:52

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Colliding Script

Very similar to a  favorite technique of mine  smile   

Examples:

Non-Rotating Sprite
http://scratch.mit.edu/projects/Paddle2SeeFixIt/188825

Rotating Sprite
http://scratch.mit.edu/projects/Paddle2SeeFixIt/188807


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#5 2009-10-30 16:14:17

67589jun
Scratcher
Registered: 2007-07-13
Posts: 1000+

Re: Colliding Script

Nobody else wants to comment?


http://i.imgur.com/I1DuR.png

Offline

 

#6 2009-10-30 16:58:11

diywid
Scratcher
Registered: 2009-10-27
Posts: 76

Re: Colliding Script

sounds like this could come in handy with my racing games, so thanks for that...

Offline

 

#7 2009-11-01 19:12:45

lonwol
Scratcher
Registered: 2008-11-10
Posts: 1000+

Re: Colliding Script

diywid wrote:

sounds like this could come in handy with my racing games, so thanks for that...

The thing is it doesn't work for top down scrollers


I host servers for money ya?

Offline

 

#8 2009-11-01 20:54:51

67589jun
Scratcher
Registered: 2007-07-13
Posts: 1000+

Re: Colliding Script

lonwol wrote:

diywid wrote:

sounds like this could come in handy with my racing games, so thanks for that...

The thing is it doesn't work for top down scrollers

It only works with things that aren't scrollers. But it does work with single-background non-scrolling things.


http://i.imgur.com/I1DuR.png

Offline

 

#9 2009-11-02 16:32:39

diywid
Scratcher
Registered: 2009-10-27
Posts: 76

Re: Colliding Script

ok... do you know any scripts for collisions in scrolling racing games, because I'm gonna be making a scrolling version soon?

Offline

 

#10 2009-11-02 17:02:04

onethousand
Scratcher
Registered: 2009-05-03
Posts: 96

Re: Colliding Script

There's another way that I think might work with scrollers. Would you like me to post that?


Ready? Defend!
http://scratch.mit.edu/projects/onethousand/741108

Offline

 

#11 2009-11-02 17:07:37

diywid
Scratcher
Registered: 2009-10-27
Posts: 76

Re: Colliding Script

yes please

Offline

 

#12 2009-11-02 17:22:43

onethousand
Scratcher
Registered: 2009-05-03
Posts: 96

Re: Colliding Script

basically this works by a hitbox system. There is a sprite [each hitbox is simply a line about the width/height of the sprite in question] for the left hitbox, right hitbox, up, and down. IF the up one is touching a sprite you want to detect collision with, the sprite sets a variable (canUp - [as in can sprite go up?]) to 0. if it is not touching whatever sprite it sets the variable to 1. There are also canRight, canLeft, and canDown variables, used by the other hitboxes. The hitboxes follow around the main sprite. And if they are touching whatever sprite, they set the right variables to the correct values.
Then, with the main sprite, the one that needs collision to be detected, when
certain keys are pressed (up, down, etc.) the sprite will only move in that direction if variables canUp, canDown, etc. are set to 1. [If canUp is 0, and up is pressed, the sprite does not move.]
http://scratch.mit.edu/projects/onethousand/743210


Ready? Defend!
http://scratch.mit.edu/projects/onethousand/741108

Offline

 

#13 2009-11-07 14:33:57

lonwol
Scratcher
Registered: 2008-11-10
Posts: 1000+

Re: Colliding Script

onethousand wrote:

basically this works by a hitbox system. There is a sprite [each hitbox is simply a line about the width/height of the sprite in question] for the left hitbox, right hitbox, up, and down. IF the up one is touching a sprite you want to detect collision with, the sprite sets a variable (canUp - [as in can sprite go up?]) to 0. if it is not touching whatever sprite it sets the variable to 1. There are also canRight, canLeft, and canDown variables, used by the other hitboxes. The hitboxes follow around the main sprite. And if they are touching whatever sprite, they set the right variables to the correct values.
Then, with the main sprite, the one that needs collision to be detected, when
certain keys are pressed (up, down, etc.) the sprite will only move in that direction if variables canUp, canDown, etc. are set to 1. [If canUp is 0, and up is pressed, the sprite does not move.]
http://scratch.mit.edu/projects/onethousand/743210

I tried this, and it went all haywire on me maybe i just did it wrong idk


I host servers for money ya?

Offline

 

#14 2009-11-09 19:17:54

67589jun
Scratcher
Registered: 2007-07-13
Posts: 1000+

Re: Colliding Script

onethousand wrote:

basically this works by a hitbox system. There is a sprite [each hitbox is simply a line about the width/height of the sprite in question] for the left hitbox, right hitbox, up, and down. IF the up one is touching a sprite you want to detect collision with, the sprite sets a variable (canUp - [as in can sprite go up?]) to 0. if it is not touching whatever sprite it sets the variable to 1. There are also canRight, canLeft, and canDown variables, used by the other hitboxes. The hitboxes follow around the main sprite. And if they are touching whatever sprite, they set the right variables to the correct values.
Then, with the main sprite, the one that needs collision to be detected, when
certain keys are pressed (up, down, etc.) the sprite will only move in that direction if variables canUp, canDown, etc. are set to 1. [If canUp is 0, and up is pressed, the sprite does not move.]
http://scratch.mit.edu/projects/onethousand/743210

Very good concept+script!  smile


http://i.imgur.com/I1DuR.png

Offline

 

#15 2009-11-13 23:47:06

67589jun
Scratcher
Registered: 2007-07-13
Posts: 1000+

Re: Colliding Script

Anyone?


http://i.imgur.com/I1DuR.png

Offline

 

Board footer