Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Point to closest?
- godbisset
-
Scratcher
9 posts
Point to closest?
sorry if this has already been answered in another thread, but i could not find it if so. How can i make a point to closest script? like the
point towards sprite1
block but for clones, such as
point towards closest sprite1.
like for a ttd game point towards closest enemy clone. Thankyou godbisset
point towards sprite1
block but for clones, such as
point towards closest sprite1.
like for a ttd game point towards closest enemy clone. Thankyou godbisset
Last edited by godbisset (March 2, 2013 15:13:04)
- godbisset
-
Scratcher
9 posts
Point to closest?
it would kinda work, but it would be to slow. it would also only work for those four direction.
The game is a planet game where the player would fall towards the closet planet but you would be able to jump to other planets gravity wells. but if it had to scan each time the person moved i just dont think it would work.
thanx anyway.
The game is a planet game where the player would fall towards the closet planet but you would be able to jump to other planets gravity wells. but if it had to scan each time the person moved i just dont think it would work.
thanx anyway.- MoreGamesNow
-
Scratcher
100+ posts
Point to closest?
I had to make a script that ran through all clones to see if any of them were within a specific range. What I did was make a list of all the clones' locations. I'd advise you to do the same and assign each clone a number that corresponds to an item of the “X list” and “Y list”. Then use the distance formula on each set of coordinates (in the code below I don't take the square root 'cause it is kind of irrelevant).
Use the wiki script here to point to the coordinates
set [i v] to (1)
set [min_dist v] to ((x_list[1]-xposition)*(x_list[1]-xposition)+(y_list[1]-y position)*(y_list[1]-y position))
set [j v] to (item (1) of [x_list])
repeat (length of [x_list]-1)
{
change [i v] by (1)
if((x_list[i]-xposition)*(x_list[i]-xposition)+(y_list[i]-y position)*(y_list[i]-y position) < min_dist)
{
set [min_dist v] to ((x_list[i]-xposition)*(x_list[i]-xposition)+(y_list[i]-y position)*(y_list[i]-y position))
set [j v] to (i)
}
}
point to coordinates: "item (j) of [x_list]" and "item(j) of [y_list]"
Use the wiki script here to point to the coordinates
- MoreGamesNow
-
Scratcher
100+ posts
Point to closest?
I don't know the specifics of your game, but I'd just use x and y velocity and trig. Having each planet's gravity affect your player no matter where s/he is is more realistic (weakening as s/he gets further away). On the otherhand, if you want your player's feet to be facing “down” towards the closest planet, the above script could be pretty useful 

- TheGamer-
-
Scratcher
100+ posts
Point to closest?
I have a tutorial on this here : https://scratch.mit.edu/projects/87684671/
- BKFighter
-
Scratcher
1000+ posts
Point to closest?
I have a tutorial on this here : https://scratch.mit.edu/projects/87684671/Please do not bring open a post over two years old if the question has already been answered.
- SuperCappy
-
Scratcher
500+ posts
Point to closest?
Seems like the topic is resolved, i will report this topic to be closed to prevent further necroposts, like this one
Last edited by SuperCappy (Nov. 18, 2020 07:34:10)
- deck26
-
Scratcher
1000+ posts
Point to closest?
Seems like the topic is resolved, i will report this topic to be closed to prevent further necroposts, like this oneNext time just report it - why necropost to say you're doing so?
- Discussion Forums
- » Help with Scripts
-
» Point to closest?