Search

Thursday, July 30, 2020

Making Scratch Projects :: Help With Scripts :: I can't create my project!

SeuAmigo35 :

awesome_guy6856 wrote:

If you're gonna want several enemies then you shouldn't be using a distance block.

You should instead store each enemy clone's X and Y values in a list

Then loop over each item in both lists (2 lists one for X one for Y) and find the closest one. Then check if that's under 326.

This is a tricky task, so let me just show you the script.

define find nearest enemy
set [lowestDistance v] to [99999]
repeat (length of [enemy X values v] :: list)
find distance from my x and y to enemy's x and y
if <(distance) < (lowestDistance)> then
set [lowestDistance v] to (distance)
end
end

To find the distance between two x-y coordinates you should use the distance formula, which is a REALLY long block. Here it is.

([sqrt v] of ([square v] of ((x position) - (enemyX))) + ([square v] of ((y position) - (enemy Y))))
where i find the
([square v] of ())
block?

from Latest posts on Help With Scripts https://ift.tt/3ffNze6

No comments:

Post a Comment