Discuss Scratch

  • Discussion Forums
  • » Help with Scripts
  • » (POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active? [RSS Feed]
Pranav_reii
Scratcher
67 posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

-TheNameless- wrote:

(#20)

Pranav_reii wrote:

This Might Help, Add This Code To The Previous Scripts! https://scratch.mit.edu/projects/619801764/editor Check Here, On Your Previous Id But Script Section 4

But Before That, You Need A Hitbox Colored, And The Door Always Has 0 (Closed) 1 (Opened), So If The Door Touches Player Then It Broadcasts A Message, The Player Detects Which Side It Hits Using A Colored Hitbox Like.



Yellow = RightCollide
Blue = Left
Red = Top
And Finally Green = Down Collision.

I would prefer it if I didn't need a separate hitbox sprite (my player is already a square), and I don't fully understand how your code works or how to integrate it. If you could, it would be great if you could create separate sprites that have all the code that they are supposed to have.

I don't understand how the Movement and Movement2 blocks work, and I don't understand the Collision custom block. If we have a special Hitbox sprite that changes costumes, why is that not done in the Collision block? In addition, the Collision block seems to check two colors, but my game uses only one color (my game is called Monochrome), so I can't make the doors or the player be a different color.

I appreciate that you tried to help though. Thanks!
Oh, I see, I Will Make a youtube tutorial for you my channel is Reii Does Scratch, Ill Finish by tomo
Coder046
Scratcher
100+ posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

The hitbox would be a costume of the same sprite. The player sets its costume back after checking for collisions, but when it is checking for collisions, it uses the hitbox costume. I would also suggest a different hitbox costume for each direction, as sprite collisions are much faster than color collisions.
-TheNameless-
Scratcher
100+ posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

Bump!
MrNanners
Scratcher
100+ posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

-TheNameless- wrote:

MrNanners wrote:

I will show you my method. for this example I will have a zombie and a human
-snipped out unworldly large script-
I am human, I make mistakes. If I got something wrong tell me :D
This seems really useful, do you have this in one of your projects somewhere? I really don't want to have to go through the hassle of recreating a script off of the forums.
lol dont worry its a lot simpler than it seems. sorry for the extremely late response i forgot to follow the discussion. In my plants vs zombies game, linked in my signature, i use this method for then “projectiles” touches a “zombies” or when “zombies” touches “plants”. You don't have to copy it block for block, but get the idea down and adapt it to your needs. Just put clones' data into lists, and interpret that data when necessary. Thats basically the entire idea
You can see the same exact code in the sprite “projectiles” under function “clone.get_id” and “clone.update_data” in my PvZ game.
You can also find the same code in sprite “zombies” under the function “clone.get_id” and under the “repeat until (clone.heath < 1)” loop under the only “when I start as a clone” block
The only reason that I don't have all my code in one sprite like you is because all of the blocks make it too laggy for me to code anything.

Last edited by MrNanners (Jan. 10, 2022 22:12:53)

Pranav_reii
Scratcher
67 posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

Coder046 wrote:

(#22)
The hitbox would be a costume of the same sprite. The player sets its costume back after checking for collisions, but when it is checking for collisions, it uses the hitbox costume. I would also suggest a different hitbox costume for each direction, as sprite collisions are much faster than color collisions.

So We Can Have 4 Different Costumes Cloned, But Clones Cant Detect Clones, So If It Is Touching A Door, We Would Need Complex Math To Detect If Clone Is Touching Clone, So Color Detection Works Best. Only If You Want A Costume To Be Cloned.
Pranav_reii
Scratcher
67 posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

Sorry, Ill Make The Tutorial Today. btw Yes It Is A Clone Of A Costume In Your Sprite. As Your Guy Is A Square, Its In fact Better.
-TheNameless-
Scratcher
100+ posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

MrNanners wrote:

-TheNameless- wrote:

MrNanners wrote:

I will show you my method. for this example I will have a zombie and a human
-snipped out unworldly large script-
I am human, I make mistakes. If I got something wrong tell me :D
This seems really useful, do you have this in one of your projects somewhere? I really don't want to have to go through the hassle of recreating a script off of the forums.
lol dont worry its a lot simpler than it seems. sorry for the extremely late response i forgot to follow the discussion. In my plants vs zombies game, linked in my signature, i use this method for then “projectiles” touches a “zombies” or when “zombies” touches “plants”. You don't have to copy it block for block, but get the idea down and adapt it to your needs. Just put clones' data into lists, and interpret that data when necessary. Thats basically the entire idea
You can see the same exact code in the sprite “projectiles” under function “clone.get_id” and “clone.update_data” in my PvZ game.
You can also find the same code in sprite “zombies” under the function “clone.get_id” and under the “repeat until (clone.heath < 1)” loop under the only “when I start as a clone” block
The only reason that I don't have all my code in one sprite like you is because all of the blocks make it too laggy for me to code anything.
I appreciate your help, but I don't see a way in your code to determine whether or not I am touching the clone. The only way I can see with your code to do that is to determine the width and height of my clones, and I don't know of a great method of doing that.

Thanks though! -TheNameless
MrNanners
Scratcher
100+ posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

-TheNameless- wrote:

I appreciate your help, but I don't see a way in your code to determine whether or not I am touching the clone. The only way I can see with your code to do that is to determine the width and height of my clones, and I don't know of a great method of doing that.
Thanks though! -TheNameless
Do you use the original sprite AND the clones? I personally wouldn't recommend doing that. I would just use only clones and use my method. the block “<touching {sprite v}>” will detect when touching the sprite, it will find the id of that clone, then it will look at the item corresponding to the id of the closest clone in the costumes list, and then you can use that to do whatever you need to do.
My method does not require finding the height and width of costumes, but you can actually find the width*height of a costume by looking under the costume name in the costume editor.
Pranav_reii
Scratcher
67 posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

-TheNameless- wrote:

(#20)

Pranav_reii wrote:

This Might Help, Add This Code To The Previous Scripts! https://scratch.mit.edu/projects/619801764/editor Check Here, On Your Previous Id But Script Section 4

But Before That, You Need A Hitbox Colored, And The Door Always Has 0 (Closed) 1 (Opened), So If The Door Touches Player Then It Broadcasts A Message, The Player Detects Which Side It Hits Using A Colored Hitbox Like.



Yellow = RightCollide
Blue = Left
Red = Top
And Finally Green = Down Collision.

I would prefer it if I didn't need a separate hitbox sprite (my player is already a square), and I don't fully understand how your code works or how to integrate it. If you could, it would be great if you could create separate sprites that have all the code that they are supposed to have.

I don't understand how the Movement and Movement2 blocks work, and I don't understand the Collision custom block. If we have a special Hitbox sprite that changes costumes, why is that not done in the Collision block? In addition, the Collision block seems to check two colors, but my game uses only one color (my game is called Monochrome), so I can't make the doors or the player be a different color.

I appreciate that you tried to help though. Thanks!


Maybe Ill Explain Here Only,

So We Have Four Colors, These Colors Detect If They Are Touching A Different Color
But The Hitbox Is Actually The Main Sprite And The Player Is A Cloned Costume From The Hitbox.

So That Makes It Easier

And Then The color Which Is Touching The Door Will Be Reported As 1 Meaning Touched On The List For Directions.

Then Only If It Is 0 We Can Move That Direction Else We Cant.
-TheNameless-
Scratcher
100+ posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

Pranav_reii wrote:

-TheNameless- wrote:

(#20)
-snipped-

-TheNameless- wrote:

-snipped-


Maybe Ill Explain Here Only,

So We Have Four Colors, These Colors Detect If They Are Touching A Different Color
But The Hitbox Is Actually The Main Sprite And The Player Is A Cloned Costume From The Hitbox.

So That Makes It Easier

And Then The color Which Is Touching The Door Will Be Reported As 1 Meaning Touched On The List For Directions.

Then Only If It Is 0 We Can Move That Direction Else We Cant.
This code allows me to determine in which direction I am touching a clone of the Entities sprite, but that isn't what I'm looking for. I'm trying to figure out what costume the clone I am touching has selected.

Thanks anyway! -TheNameless

Last edited by -TheNameless- (Jan. 18, 2022 14:16:24)

MrNanners
Scratcher
100+ posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

-redacted- i was wrong, will revise soon

Last edited by MrNanners (Jan. 18, 2022 18:36:42)

MrNanners
Scratcher
100+ posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

okay I made a remix here, with a working variable that detects when touching a door.

The issue is in the functions “On Ground Collision”, “Check for Collision…”, and “Touching Closed Door?”

In brief, the movement during the collision detection will cause “Touching Closed Door” to only say “no” because the sprite is above the entity.

I noticed that when you are standing on the Door, and you press “up arrow”, “_touching_door” will say “yes” for 1 frame

Last edited by MrNanners (Jan. 18, 2022 19:02:42)

Pranav_reii
Scratcher
67 posts

(POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active?

Oh I See, Lemme Code.

Done See https://scratch.mit.edu/projects/619801764/editor/ And Try Find

defineBroadcastTouchingDoorKeyNumberAnd Check For The Whole Code As I Updated All
  • Discussion Forums
  • » Help with Scripts
  • » (POTENTIALLY CONFUSING) How do you detect if a certain sprite is touching a clone, but only if that clone has a certain costume active? [RSS Feed]

Powered by DjangoBB