Discuss Scratch

moonheart08
Scratcher
24 posts

How would i tell which direction a sprite is touching a color from.

what i mean is like: color red north
Any help and a example script?
i need it for this: https://scratch.mit.edu/projects/109570569/#editor (don't mind the ugly coloring, it is due to be changed to different shades of black)

Last edited by moonheart08 (May 13, 2016 16:36:35)

drmcw
Scratcher
1000+ posts

How would i tell which direction a sprite is touching a color from.

One way is to have multiple costumes that cover North, East, South and West of the sprite and you can switch to each costume in turn and do a touch check to work out if touching above, below, left or right. You could add more costume if you wanted more accuracy but would also slow things down.
moonheart08
Scratcher
24 posts

How would i tell which direction a sprite is touching a color from.

drmcw wrote:

One way is to have multiple costumes that cover North, East, South and West of the sprite and you can switch to each costume in turn and do a touch check to work out if touching above, below, left or right. You could add more costume if you wanted more accuracy but would also slow things down.
Thanks! I think saving the position of the object and subtly changing it might work a little better (your post help me come up with that)
Specter22
Scratcher
100+ posts

How would i tell which direction a sprite is touching a color from.

You could use sensor sprites also like so https://scratch.mit.edu/projects/109569917/ no matter what color or colors the level is you are sensing the sprite not the color.
piggiety
Scratcher
65 posts

How would i tell which direction a sprite is touching a color from.

You could also make each side of the sprite a slightly different color and use a
if <color [#00ff00] is touching [#0000ff] ?> then

end
block.

Hope this helps!
Wtib2013
New Scratcher
17 posts

How would i tell which direction a sprite is touching a color from.

I think it would be hard to do this with color, but you might be able to do it with sprites.
Assume you have sprite A (mario) touching sprite B (a turtle). Assume you want mario to die when touching the Turtle, unless Mario jumps on the Turtle.

Two options,

(1) What if you say,
if Mario is touching Turtle, then,
If Y position of Sprite A > Y position of Sprite B, then
Kill Turtle
Otherwise, Kill Mario

The would require you to know where Mario and the Turtles are at all time. It might allow Mario to jump a little late and still be above B, and kill the Turtle.

(2) if you want mario to only kill turtles when he is jumping (or even on the downward part of a jump, you might be able, create a status “is Jumping”, and have it normally at 1, but change to 2 when jumping (or when moving down jumping) and use a similar logic to above.
if Mario is touching Turtle, then,
If Mario “is jumping” = 2, then
Kill Turtle
Otherwise, Kill Mario
Yeetoburro1
Scratcher
1000+ posts

How would i tell which direction a sprite is touching a color from.

Wtib2013 wrote:

I think it would be hard to do this with color, but you might be able to do it with sprites.
Assume you have sprite A (mario) touching sprite B (a turtle). Assume you want mario to die when touching the Turtle, unless Mario jumps on the Turtle.

Two options,

(1) What if you say,
if Mario is touching Turtle, then,
If Y position of Sprite A > Y position of Sprite B, then
Kill Turtle
Otherwise, Kill Mario

The would require you to know where Mario and the Turtles are at all time. It might allow Mario to jump a little late and still be above B, and kill the Turtle.

(2) if you want mario to only kill turtles when he is jumping (or even on the downward part of a jump, you might be able, create a status “is Jumping”, and have it normally at 1, but change to 2 when jumping (or when moving down jumping) and use a similar logic to above.
if Mario is touching Turtle, then,
If Mario “is jumping” = 2, then
Kill Turtle
Otherwise, Kill Mario
Hi! Thanks for trying to help. However, you just necroposted, as this topic is over 4 years old! Please check the date of the topic before posting.
Scratch on!
rojo08_the_real_one
Scratcher
5 posts

How would i tell which direction a sprite is touching a color from.

i tried this
when green flag clicked
forever
if <<(y position) < (thing y)>
> then broadcast [ loose]


else

end
end

i hope i did that right

Last edited by rojo08_the_real_one (March 19, 2021 13:20:12)

Powered by DjangoBB