Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Of course
We don't really have a game unless our sword ability can actually kill an enemy
So
Let's go ahead and do that
A couple of things that we need to do the first question that we need to answer it
How do we know where are the enemies are
In the
And the way that were going to do that as we're going to use a strategy similar
To Howie
The player position from the game camera
I'm going to add
The enemy
2 and 10
Is group
So let's go ahead and
Go into a basic enemy by clicking on
The icon from the main theme
And when I click on the route
I'm going to click on the
No
Dark
Tabs
Guiding click on
And then we're going to add
The
Anime to
Ok
So now anime is in the anime group
Let's go to our sword ability Now control shift to open
Quick opensea
Can you get your sword ability controller in open that up
Subtitled by online-courses.club We compress knowledge for you!
And then click the Script icon to open up the screen
So we're currently spawning a sword in
At the player
But we probably want to spoil the song
Instance
So how are we going to do that
We're going to get rid of this black here we're getting a fur
No dim repair where to change this to
Enemies is equal to
Get nodes
In
And then
Ok and then we're going to need to do a simple check here we're going to get rid of player lying here
And then I'm here we're going to say if enemies
Shot size
Is equal to 0 which means that we have no elements in the array does no enemies
The screen will just going to return out of that
So that we don't even try to spawn the sort of there's no
Ok now we're gonna get an error here and that's fine I'm just going to comment this out for now by hidden control
And then
Ok
So control cable automatically comment there was line so they don't
Take off
And there is one thing that we want to do with his enemies which is
We were
How to only get the enemy
Is that are within a certain distance of
The player
Because if there's an enemy that off screen we don't want the sword which is kind of like a melee ability
To be able to hear that
So let's declare a constant
Up here
Con
Max Rayne
I want to set it to something like
104
So there is a Max
Configurable if you want
By doing
At
Export
Bar
Mark
Range
You can do that if you want it to be configurable
My inspector
Right here
Music on speakers I don't foresee this variable needing to be changed
At all
So we're going to go back down to her on time or time out here
I'm going to say enemies
Is equal to enemies dot
So what we going to do is we're going to pass on
Filter mesh
So in the filter function
We can actually pass what is called
Filter function
Which is
A function that takes each element in the array
Argument
And can return either true or false
To decide
Whether that element should be preserved in the for
So you can imagine like a real life filter
You have it blacked out
Certain things so if you have a water filter
It let's all the waters there's a film
An
Prevents all the sediment from
So it's the same way with
Filter function with data
With an array
We can run a function against each element to the term
If that element should be filtered
Or not
And so in here what I'm going to do is it going to rain
Funk
And then parentheses enemy
We're going to specify this enemy is a type of no 2D
So that we can get suggestions
I'm going to call
Return
Anime
Global position
Distance squared
Tool
And we're going to check
The distance squared to the player
Position
Is
West Ham the maximum
Before we do that we're going to make this a little bit nicer by
Formatting as well babe
So if I go to my return key word here and I just press
Enter to create a new line
We can do that and then I need to move the end parentheses of you highlight Apprentice
It will show you where the matching printer
Underline underneath of parentheses
You can see that
Is underlined the
Opposing for a disease over here to begin
The filter
Funk
And so just before that one I'm going to hit enter again
Depressed
Tab to unintended
To preserve the proper in
And then here we still got an error but if we want to see if this works I can just take control care
To come in
Indent there's a couple of times
And then
Return
Solicitor very barebones filter function that will just feel throughout everything
So this Returns true
Element Andrew
Well described the elements so if we were the right like this we were filled out every single
I'm just going to keep it there for now just as demonstration purpose
We do need to
The player position
Again then
I'm gonna put that line back that we had before
Vera-playa equals get three dots
First
No dim
Claire
As note
Ok so back to our filter function I'm going to remove this hard couldn't fault here
I'm a presscontrol k on this line
To remove
The car
And then remember what we doing here is worth checking
If the distance
Square
2
The player
Is greater than
The match
Range
Or in this case we wanted to be less than the maximum sort Returns true
And preserve the
And again we're doing distance squared to because
Square calculation actually required
Fewer CPU Cycles compared
Atypical
Square root operation
And so when you're dealing with large list
This was actually
Match
So distance squared to
What can I put in as the argument there
Player
Dot global position
And then we're going to say is last
How
Max range
2
So when you do a Distance squared to check
This is going to get the squared
From the enemy to the player
That means that the Range that were checking also
To be square
So instead of using
Match range we have to use mate
Change x Max
Squared
So again this will filter out
Every Anna
That is further than
150 pixels away
From the player
And we're signing it here
Right enemies is equal to enemies that filter
Because this filter function
If I bring up my documentation
By clicking F1
On my keep
If I look
Theory test
And click
I can scroll down
And find
Motor function
And you can see that the return type
Is listed
Arsenal left of the filter
So it's going to return a new array
So and you can read the documentation as well
Which will tell you here
It returns a new array
So again the documentation is always there if you're confused about anything that I'm going over
Please feel free
Pause the video
Open up the door
Station
And just do a little bit of Reading if something I'm saying is
But moving on
2
The rest of this
So now we've got our filter Denham
All the animals are close enough to the play
To be able to use the sword ability
I'm sorry we're going to want to put that cheque back into
So
Where is equal then now
So can't be too
Ok so now we've got Oliver check down in Oliver
Setup done
Now we actually want to take
Closest enemy in attack on that
So I want to do is wee wee
Call enemies
Darts
Cus
And in here within a provide a sorting function
Which is
Funk
No to die
Karma
For a second
B
Colin no to do so again
Or typing elements
And then a cold
The end of that
But hit return and then unindent
So that way with God are formatted correctly
And just a quick note about the Sorting function so the way that sorting works across a Friday
Languages is Dad new passing a function
That Compares element 88 helmet
So it gives you
Pairs at a time
And you as the developer
To tell
Weather
It should be sorted before
B and
Works the same way in Jesus Christ
We've got our a enemy and our
B&M
And we're going to grab the Disco
To the player for each of those enemies
And then return true
If a is closer because we want a to be sorted
First is this is unclear what you can do is again open up your documentation with f
You can actually
Bye
The method name that you're having trouble
Type
Sort custom here
That brings me right to the erase awesome and I can click into that
And this will give me a lot of useful information
How does sorting actually work
Any point doing this you're unsure of the exact behaviour of a function that were using the overall pass
Video open up the documentation in read
What
Function
Does
So we need to grab the a Distance so a underscore distance
Is equal to
A global position
Where can you use distance squared to again for the same reason that we did above
Inside edition
Squared to the player global
Subtitled by online-courses.club We compress knowledge for you!
I'm just going to keep that
Unless duplicate this line solutions copy and paste
I'm going to change this
Be distance
And be very short to change this to be Da Club up
I know we're just going to return a distance
Is less than
So again if this
Sorting function Returns true that means that a should be sorted
Before
B
Andover minor type of here this needs to be 2D
Capitalise
What is fixed
So now we got a sorted Enemy Away
And we already know that the enemy size is greater than 0
So
Replace this comment out line
So player get parent and Child
Ring keep this line actually because we're going to tell the sword to go into the tree somewhere for keeping this line to add child
What we're going to change is the global positions what's on comment that line as well
Instead of playing at global position
What we're going to do is ringing to say enemies
At index 0
So the first enemy
In the sorted array
Will be the closest anime
And it will be a
That
So let's go and test this but first let's go back to our main scene
And click on the 2D
Set the top to go bye
2 hour
Scene view
And I'm just going to go ahead and duplicate this enemy by selecting it and pressing ctrl d
And I've got a second-hand
I'm going to hit w
To enable the move tool
Then I'm going to move that second enemy
Fire away
So let's go ahead and play
I can see that the sword is always attacking this rat first
Because that's the closest one now if I switch directions
Responding on that one
Now that we've got the sword tiling the proper anime
Wheel cover
How to actually make the sword kill the enemy in the next lesson
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.