Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make a turret shoot at a clone?
- ht12048
-
3 posts
How to make a turret shoot at a clone?
Hi I have tried looking at other topics asking this but the answers don't have enough explanation or anything. Does anyone know an easy way to point at the closest clone? If you do can you please explain in depth. Thanks. http://scratch.mit.edu/projects/50979476/ is the project im trying to do this for.
- deck26
-
1000+ posts
How to make a turret shoot at a clone?
If you only have one shooter you could give each clone a number and have a list containing the distances using the
block. Then, in a custom block, find the lowest distance. So, for example, item 5 in the list is the distance from clone 5 to the shooter.
- ht12048
-
3 posts
How to make a turret shoot at a clone?
If you only have one shooter you could give each clone a number and have a list containing the distances using theblock. Then, in a custom block, find the lowest distance. So, for example, item 5 in the list is the distance from clone 5 to the shooter.
Do you know what I would put in that block? And I am new to lists so how would they work?
- deck26
-
1000+ posts
How to make a turret shoot at a clone?
I recommend looking at http://wiki.scratch.mit.edu/wiki/List if you're new to lists.
To give each clone a number you need a local (for this sprite only) variable for the sprite. Let's call it CloneID.
So that's the first stages
To give each clone a number you need a local (for this sprite only) variable for the sprite. Let's call it CloneID.
would create 10 clones, the first would have CloneID=1, the next CloneID=2 etc.
would keep the distances up to date.
So that's the first stages
- deck26
-
1000+ posts
How to make a turret shoot at a clone?
Then for the custom block you go through the list of distances to find the smallest value.
So how does the turret know where that clone is? One option would be to have global x and y variables that a clone will change if it's the current one. Then get the original sprite to stay hidden but go to those coordinates and point the turret at the sprite.
So at the end of the green flag script in the earlier post add
and have an addition clone script
I think that does it.
would set ‘whichclone’ to the clone ID for the nearest clone.
So how does the turret know where that clone is? One option would be to have global x and y variables that a clone will change if it's the current one. Then get the original sprite to stay hidden but go to those coordinates and point the turret at the sprite.
So at the end of the green flag script in the earlier post add
and have an addition clone script
I think that does it.
- ht12048
-
3 posts
How to make a turret shoot at a clone?
So would these scripts be put into the sprite I want to aim at, or the turret that aims at them?
- Scrachrulz
-
42 posts
How to make a turret shoot at a clone?
Put them into the sprite that is being cloned (and aimed at). Then add a “show” block at the start of one of the “when I start as a clone” headers, and tell the turrent to forever point toward the other sprite. @deck26 great script, by the way! I actually didn't know that local variables create a new instance of themselves for each clone; I'll use that in the future!
- deck26
-
1000+ posts
How to make a turret shoot at a clone?
The green flag script that creates clones has to be in the sprite being aimed at or the local cloneID variable won't work. Obviously ‘when created as sprite’ scripts have to be for the same sprite. So would these scripts be put into the sprite I want to aim at, or the turret that aims at them?
The main thing to avoid with the custom block is running it for multiple clones as it looks at them all anyway. So it could be in a forever loop for the turret or in the green flag script for the other sprite - the latter, just before the goto x,y should work.
As @Scrachrulz points out I should have included a show at the start of one of the ‘when started as clone’ scripts.
- dbossinger
-
19 posts
How to make a turret shoot at a clone?
But how do you get the turret to aim at the clones?
- jokebookservice1
-
1000+ posts
How to make a turret shoot at a clone?
I won't be using it in any of my projects though I am using it in my masters of steam series, if you want to check it out.This is both spam and a necropost. Please be aware that spamming is reportable. This is a good tutorial.
The easiest method is to create a hidden sprite that uses the Go to X: Y:, and then use (point towards ), but it can also be done with trigonometric functions. But how do you get the turret to aim at the clones?
Just to repeat: Please do not spam or necropost. This topic is almost a year old.
- Zarif973442050
-
23 posts
How to make a turret shoot at a clone?
I am making a game based off Warfame's shooter game, and I personally think that the easiest way to do it is to make the turret have two parts; 1: The base of the turret, and 2 the turret's barrel itself. Make it so that the barrel of the turret always goes to the base, and make it point at the zombie. In my case, I would say (sry can't put the code blocks, my mac is being trash rn) point towards zombie, and create a clone of laserbullet. This makes it so that the turret points at the zombie clone (which is treated as the zombie) and shoots at it too! I hope that solves your problems. (I know there are a lot better and complicated ways, but I'm just starting out).
- Discussion Forums
- » Help with Scripts
-
» How to make a turret shoot at a clone?