Discuss Scratch

Nbjabe_on_scratch
Scratcher
5 posts

How to convert X and Y positions in different lists into a direction

Im making a Plants vs Zombies fan game called Plants vs Zombies 3,im using a technique that this youtuber used to make his Plants vs Zombies game less laggy: he used lists to store the zombies x and y positions. So i decided to do the same but now im trying to make a new plant that targets the closest zombie to the house but im having problems trying to make the bullets point to the first zombie using lists. This is my first time doing something like this so i'm having trouble, here's what i have currently.

When flag clicked
show
Point in Direction: (Join) (Join / Item 2 of ZombiePositionsX / (space) ) (item 2 of ZombiePositionsY)
Repeat until touching (Edge) or (Zombie)
Move 5 steps
Delete this Clone

Any tips or help?
My browser / operating system: ChromeOS 14541.0.0, Chrome 130.0.0.0, No Flash version detected
RBlueCakes
Scratcher
40 posts

How to convert X and Y positions in different lists into a direction

Do you mean find the direction of 4 or 3 x and y positions? because I don't know if I understand the problem or not?

whenIreceivestart codingrepeatuntilcoding done?=yessetcodetoyesifhard to fix error=yesthenchangerageby99999999999ifgamestate=finishedthensetpost to studiostoyes

Last edited by RBlueCakes (Jan. 2, 2025 17:13:15)

DragonPlusMaster
Scratcher
100+ posts

How to convert X and Y positions in different lists into a direction

Nbjabe_on_scratch wrote:

Im making a Plants vs Zombies fan game called Plants vs Zombies 3,im using a technique that this youtuber used to make his Plants vs Zombies game less laggy: he used lists to store the zombies x and y positions. So i decided to do the same but now im trying to make a new plant that targets the closest zombie to the house but im having problems trying to make the bullets point to the first zombie using lists. This is my first time doing something like this so i'm having trouble, here's what i have currently.

When flag clicked
show
Point in Direction: (Join) (Join / Item 2 of ZombiePositionsX / (space) ) (item 2 of ZombiePositionsY)
Repeat until touching (Edge) or (Zombie)
Move 5 steps
Delete this Clone

Any tips or help?
My browser / operating system: ChromeOS 14541.0.0, Chrome 130.0.0.0, No Flash version detected
Could you maybe make your coding on the forum scratch blocks? Or share the project?

Is this the code?

whenIstartasacloneshowpointindirectionjoinjoinitem2ofZombiePositionsXitem2ofZombiePositionsYRepeatuntiltouchingedge?ortouchingZombie?Move5stepsdeletethisclone

First thing I noticed is that you had the when green flag clicked, and had it delete this clone. It's not possible to delete a clone in any script except the when I start as a clone block script. I don't know if this is just a typing error or not-

Further emphasis on sharing the project. It would make it much easier for us to help you! Thanks!

Last edited by DragonPlusMaster (Jan. 2, 2025 17:35:22)

Arcplayz_
Scratcher
88 posts

How to convert X and Y positions in different lists into a direction

For the point in direction code, go here, click look inside, and backpack the script at the bottom. Then go to your project, put the script in there, replace the ‘point in direction’ with the ‘point towards (x) (y)’ block, and put in your lists.

https://scratch.mit.edu/projects/87161928/

Last edited by Arcplayz_ (Jan. 2, 2025 17:39:43)

Nbjabe_on_scratch
Scratcher
5 posts

How to convert X and Y positions in different lists into a direction

@DragonPlusMaster Yes! thank you for translating it into blocks. Its kinda hard to do it for me so thanks again for doing that. anyway i need to find out how to make it target a specific position from 2 lists, one that has the X and the other the Y position. Im gonna make a blank project with just the code so its somewhat easiier to understand

Powered by DjangoBB