Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do I make a sprite point towards a clone?
- Squidy66
-
Scratcher
5 posts
How do I make a sprite point towards a clone?
I need some help making a sprite point towards a clone I have absolutely no idea on how to do it, very confusing. Although I know its possible because I have played a game where that happened.
- PureMichigan
-
Scratcher
100+ posts
How do I make a sprite point towards a clone?
I need some help making a sprite point towards a clone I have absolutely no idea on how to do it, very confusing. Although I know its possible because I have played a game where that happened.Are you sure that it was a clone not just a duplicate sprite? I just tried to do it, and i can't think of a way…while pointing to another sprite is easy.
- deck26
-
Scratcher
1000+ posts
How do I make a sprite point towards a clone?
Each clone has it's own x-y coordinates. If you store these in lists indexed by clone-number (so first item in list xpos is the x-position for clone 1 etc) then you can point towards that clone - the easiest way is probably a ghost sprite that goes to the coordinates and you just point to the ghost sprite.
- Squidy66
-
Scratcher
5 posts
How do I make a sprite point towards a clone?
no its a clone, like if have a sprite and i tell it to create a clone 40 times i want another sprite to be able to point towards the clones. Super Tricky.
- deck26
-
Scratcher
1000+ posts
How do I make a sprite point towards a clone?
Not that tricky really - see http://scratch.mit.edu/projects/46472058/
- ianrocks
-
Scratcher
47 posts
How do I make a sprite point towards a clone?
I need some help making a sprite point towards a clone I have absolutely no idea on how to do it, very confusing. Although I know its possible because I have played a game where that happened.This is actually INCREDIBLY easy. Here it is in steps:
1. Each clone must have its own special number
when I start as a clonewhere the clone's number is equal to the number of clones on the board when it was created. (Ex: the first clone created would have a number 1, second clone created would have a number 2, etc.)
set [my# v] to [1 ]
2. Each clone stores its coordinates in two separate lists, at the number in the list that corresponds with its own number
replace item (1 v) of [CloneX v] with [ (x position)]
replace item (1 v) of [CloneY v] with [ (y position)]3. Depending on which clone you want to point towards, here is the formula:
if <(item (1 v) of [CloneX v]) > [(x position) ]> thenInstead of putting 1 for the items, it can be any number, as long as it isn't greater than the number of clones created.
point in direction ((90) - ([atan v] of (((item (1 v) of [CloneY v]) - (y position)) / ((item (1 v) of [CloneX v]) - (x position)))))
end
if <(item (1 v) of [CloneX v]) < [(x position) ]> then
point in direction ((-90) - ([atan v] of (((item (1 v) of [CloneY v]) - (y position)) / ((item (1 v) of [CloneX v]) - (x position)))))
end
Here's an example of the formula put to use: http://scratch.mit.edu/projects/30941872
(the formula can be found in any of the tower sprites, in the block “Find Closest”)
- TheLogFather
-
Scratcher
1000+ posts
How do I make a sprite point towards a clone?
I made a quick remix of deck26's project (linked above), to show an alternative method which avoids using lists.
http://scratch.mit.edu/projects/46943430/
Hope that's helpful!
http://scratch.mit.edu/projects/46943430/
Hope that's helpful!
- silverCreeper356
-
Scratcher
18 posts
How do I make a sprite point towards a clone?
I need some help making a sprite point towards a clone I have absolutely no idea on how to do it, very confusing. Although I know its possible because I have played a game where that happened.This is actually INCREDIBLY easy. Here it is in steps:
1. Each clone must have its own special numberwhen I start as a clonewhere the clone's number is equal to the number of clones on the board when it was created. (Ex: the first clone created would have a number 1, second clone created would have a number 2, etc.)
set [my# v] to [1 ]
2. Each clone stores its coordinates in two separate lists, at the number in the list that corresponds with its own numberreplace item (1 v) of [CloneX v] with [ (x position)]replace item (1 v) of [CloneY v] with [ (y position)]3. Depending on which clone you want to point towards, here is the formula:if <(item (1 v) of [CloneX v]) > [(x position) ]> thenInstead of putting 1 for the items, it can be any number, as long as it isn't greater than the number of clones created.
point in direction ((90) - ([atan v] of (((item (1 v) of [CloneY v]) - (y position)) / ((item (1 v) of [CloneX v]) - (x position)))))
end
if <(item (1 v) of [CloneX v]) < [(x position) ]> then
point in direction ((-90) - ([atan v] of (((item (1 v) of [CloneY v]) - (y position)) / ((item (1 v) of [CloneX v]) - (x position)))))
end
Here's an example of the formula put to use: http://scratch.mit.edu/projects/30941872
(the formula can be found in any of the tower sprites, in the block “Find Closest”)
how do you get that? /scratchblocks
Last edited by silverCreeper356 (April 9, 2016 23:05:46)
- edevidal0
-
Scratcher
1 post
How do I make a sprite point towards a clone?
How do you keep track of this while all the clones are moving?I need some help making a sprite point towards a clone I have absolutely no idea on how to do it, very confusing. Although I know its possible because I have played a game where that happened.This is actually INCREDIBLY easy. Here it is in steps:
1. Each clone must have its own special numberwhen I start as a clonewhere the clone's number is equal to the number of clones on the board when it was created. (Ex: the first clone created would have a number 1, second clone created would have a number 2, etc.)
set [my# v] to [1 ]
2. Each clone stores its coordinates in two separate lists, at the number in the list that corresponds with its own numberreplace item (1 v) of [CloneX v] with [ (x position)]replace item (1 v) of [CloneY v] with [ (y position)]3. Depending on which clone you want to point towards, here is the formula:if <(item (1 v) of [CloneX v]) > [(x position) ]> thenInstead of putting 1 for the items, it can be any number, as long as it isn't greater than the number of clones created.
point in direction ((90) - ([atan v] of (((item (1 v) of [CloneY v]) - (y position)) / ((item (1 v) of [CloneX v]) - (x position)))))
end
if <(item (1 v) of [CloneX v]) < [(x position) ]> then
point in direction ((-90) - ([atan v] of (((item (1 v) of [CloneY v]) - (y position)) / ((item (1 v) of [CloneX v]) - (x position)))))
end
Here's an example of the formula put to use: http://scratch.mit.edu/projects/30941872
(the formula can be found in any of the tower sprites, in the block “Find Closest”)
how do you get that? /scratchblocks
- Discussion Forums
- » Help with Scripts
-
» How do I make a sprite point towards a clone?