Discuss Scratch

JoyBoy77777
New Scratcher
6 posts

How do I get my sprite to sense another sprite?

Hi folks,

New scratcher here, looking for some help. I've been trying to make a very simple “open world” style game as my first project. One where a character (sprite 1) looks like they're moving around but stays in the center and the background (sprite 2) is what is actually moving around. Now my background is a large map with 2 colors, beige and green. I want to make it so that sprite 1 can only move in the beige area where it begins and not be able to access the green. Any advice on how to implement this?
Koamodo975
Scratcher
1000+ posts

How do I get my sprite to sense another sprite?

You could use the Scratch Prime movement & collision system:
ifkeyup arrowpressed?thenchangeyby10iftouchingcolor?thenchangeyby-10 I'm not exactly sure how to work the colors for this
Edit the numbers accordingly, just make sure that both move blocks are the same, except for being opposites. Do the same thing with the other keys.
JoyBoy77777
New Scratcher
6 posts

How do I get my sprite to sense another sprite?

Hey thanks for the help! However, I don't think this works. You see Sprite 2 (my background in this case) is constantly in contact with Sprite 1 (the main character on the centre). I need the backwards movement only to apply when Sprite 1 touches a specific colour on Sprite 2.

Here's some of my code for Sprite 2:

defineLeftifkey up arrowpressed?thenchangexby10ifcoloristouching?thenchangexby-10

The first colour is the colour in Sprite 2 (background) that I want to be inaccessible and the second colour is the colour of Sprite 1 (the main character). I have tried switching these colours around and have received the same result.

Then here's how I implement this:

whenclickedsetxto-22setyto286foreverLeft

The result is that Sprite 1 is able to easily seem to walk into inaccessible areas when moving left. Whether or not the following code is in the function “Left” seems to make no difference:

ifcoloristouching?thenchangexby-10

Any ideas what I am doing wrong?

Last edited by JoyBoy77777 (July 16, 2024 20:00:08)

Powered by DjangoBB