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.

Offline
nice, i downloaded it
Offline
Very similar to a favorite technique of mine
Examples:
Non-Rotating Sprite
http://scratch.mit.edu/projects/Paddle2SeeFixIt/188825
Rotating Sprite
http://scratch.mit.edu/projects/Paddle2SeeFixIt/188807
Offline
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.

Offline
There's another way that I think might work with scrollers. Would you like me to post that?
Offline
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
Offline
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
Offline
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!

Offline