Tuesday, December 27, 2016

Youtube daily report Dec 27 2016

In the last video we saw how to give our units some basic stats

and the ability to attack their enemies

In this video we're going to be implementing some HP bars

for our units and our enemies

and floating text so that we can see

how much damage was dealt in every hit

the only new element in our scene is that now every unit has an HP bar

and also every enemy has one of those

also in our project, we're going to need to have

one floating text prefab

lets take a closer look to one of our HP bars

the HP bar is just an UI Slider, you can create one right here

by selecting UI and Slider

set to an World Space Canvas

in these elements we also have

an HP bar position script

now in the actual slider

the first thing we're going to do is to disable the handle

and the handle slide area

because our Slider wont be interactable

the only 3 properties we care on our slider are* the

max value, the minimum value and the current value of the slider

that's everything we need

of this component, that's everything we're going to be using of this Slider

our HP bar position script only has 3 variables

a distance in Y, a distance in Z and a transform for the owner of this HP bar

On the Update() of this script

the first thing we're going to be doing is to set the euler angles of our canvas

equal to the euler angles of our main camera

this is so that the HP bar is always going to be looking directly at the camera

now we're going to make a new Vector3

and set it to the owner position but

with a slight variation in the Y axis and the Z axis

then we're going to set this new Vector3

to the position of the transform of our HP bar

Now lets take a look at our floating text script

this script is also very short

and the only thing it does is on the initialization

it sets the damage variable we assign to it

to the text of the text mesh that is going to be

the actual text we're going to see

then, it does the same thing we did with

with the HP bars

it sets the text mesh object's

euler angles

equal to the euler angles of our main camera

so that our floating text are also always going to be looking at the camera

now let's see how this floating text works

when we hit play, we can see that the object

gets the value we have on the floating text script

then it does this animation where it goes up

gets bigger then shrinks and then it deletes itself

now, to make this animation the first thing we have to do is to select the object on the hierarchy

that we want to animate

then we have to open the animation window which is right here

I have it already opened

and we have to make this animation

now on the animation window we have to select the properties of the object that we want to animate

in this case we are going to be using the position and the scale of the object

then with this button right here we're going to add keyframes

to our animation

and on those key frames we're going to set the values right here on the object itself

that we ant the object to have

on that key frame

so, let's take a closer look at that

we can expand the properties that we are animating in the animation window

and if I hit play

we can see the animation looping and happening in our scene

let's see, on the first key frame

we have a Y position

of zero

and in the last key frame

we have a Y position of 1.5

that's everything you have to do to make the object go from

down to up

to animate the scale of the object you have to do the same

you have to go to the key frames of your animation

and assign the values you want

that property of the object to have

as you can see, on the first key frame we have a scale of zero

on the second key frame we have a scale of 1

we keep that scale on the third key frame of our animation and on the last key frame

we go to a scale of zero

the animation window or the animation system is going to

handle the

interpolation of these values automatically

if you want to see what's really happening you can also open the curves of the animation

as you can see here is how the scale is going to vary

it's a nice curve, it's not a linear variation like we have in the position

there is one last thing to say about this animation

as we can see here

we have an event named DestroyMe

to add events to an animation just use this button right here that is named add event

so let's see this event

when we click it we can see that in the inspector we have the animation event

and the function DestroyMe()

in these animation events we can access

any function that is present on the scripts

that the object you are animating has (some restrictions in apply*)

so we can use the

DestroyMe() that we have on the bye text script

trough this animation event

and that's it, that is how our floating text does everything it does

so now, we have these HP bars and these floating texts but how do we use them?

now we have to see our root script

and we can see we have some new variables on our Root script

first, under the other section

we have

a reference to our HP bar

a fade time set to 6 seconds

and a reference to the floating text that

is going to be our floating text prefab that we're going to be instantiating every time

this unit takes damage

in order to do so we have to add some

functionality to our take damage function

remember, the function that we use when we hit the units

and now we have a section for our HP bars and a section for our floating texts

the first thing we have to do to use our HP bar is to set it's values

on the initialization of our Root script

as you can see, we set the maximum value of our HP bar to the initial HP of the unit

also, we do the same with the current value of our HP bar

also we Invoke our FadeLifeBar function

with a delay of fadeTime

let's take a look at this FadeLifeBar()

this function is only to hide the HP bar

if our unit has

it's maximum HP

because if the unit is already full of HP

we don't need to see the HP bar

so when this function is executed

we check if the current value of the HP bar is equal to it's max value

and if it is, we set the HP bar game object to inactive

so back to our TakeDamage()

one we get our realDamage and our

HP after this damage

what we have to do is to make sure that our HP bar is active

and set it's current value to the Hp of the unit

also we Invoke the FadeLifeBar()

because in the future we're going to have some healing abilities

the only thing we have to do to use our floating text is to instantiate a copy of our floating text prefab

just a little over the position of our unit

so that it looks a little better

the animation of our floating text is going to take care of the rest

also, we have to set

the damage property of our floating text script

to the real damage we just calculated the unit is going to receive

and that's it, that's everything you have to do to give our units their HP bars and to have some floating text in our combat

on the next video we're going to be making some distance attacks with projectiles and also healing

so if you have any questions leave them in the comments and thank you so much for watching this video~

For more infomation >> Unity Tutorial: HP Bar / Life Bar and Floating Combat Text - Simple RTS [Creating Games! ~ A-7] - Duration: 11:27.

-------------------------------------------

Unity Tutorial: Enemy AI (Combat, Movement, Spawn, Alert) - Simple RTS [Creating Games! ~ A-9] - Duration: 16:15.

On the last video we saw how to make attacks from a distance using projectiles and also how to do some healing

in this video we're finally going to gice our enemies the ability to attack, move around and

we're are also going to be making a simple spawn system for our enemies to be spawned on the scene

and we're going to give our enemies a system to... An alert system so that they can tell their friends

when they spot one of our units, the first thing we have to define to give our enemies some intelligence

is their State Machine, remember that in the case of the units, the movement state was the one with the highest priority

but for the enemies, the combat state is going to be the one with the highest priority

before looking at the scripts that give our enemies their new abilities, let's see a little change that was made to the Root script

remember our TakeDamage() function that we used to deal damage to the units? well now

when the HP reaches zero, instead of directly destroying the object we first check if that object

is one of our units and if it is, we deactivate the unit and use our new KirRevive function

to reactivate that unit with a 5 seconds delay, now our kir revive function just

what it does is just to refill the HP, updates the HP bar and as I said

it reactivates the unit's GameObject. Now the scripts that allow our enemies to attack are pretty much the same scripts

that our units use but with a few differences the first difference is that

they no longer look for the "Orc" tag on the detection list, of course because they need to look for the units

not other enemies and the other difference is that they don't check if

they are not in the movement state before changing to the combat state because as I said

when it comes to enemies, the combat state takes priority over every other state the last difference is that

when they have no more enemies on the detection zone or in this case, when the enemies have no more units

on their detection zone they don't go back to the idle state, they go back to the moving state

and of course the script for our ranged enemies have the same 3 differences, first

the change of the detection tags, second, the change of the state machine conditions

and finally, the state that the unit goes when it is no longer in combat

now let's see how our enemies move around, as you can see, there are now a series of waypoints in our scene

and these are going to serve as the points where the enemies are going to move to

in a certain order, each way point is just a transform witch a sphere collider

and the enemy WayPoint script on it, let's see how it works, we have this little "Orc" right here and when we play the scene

we can see that it goes to the moving state it goes to whatever next way point the first way point tells it to go

and when it reaches the way point it waits for a bit and goes moving again to the final way point

this is the script of our way points, we can see it only has 3 variables so it's really simple

2 booleans to indicate if this is the first way point or the last way point and an array

of possible next way points, in this script we're only going to use the OnTriggerEnter() function

and when an object enters this trigger collider, we check if the tag is "Orc" to see if

the object is one of our enemies, then we check if this way point is marked or is identified as

the last way point, if it is, then we tell that enemy that his next way point is going to be nothing

so we're going to get that enemy moving script which we're going to see in a while

and we're going to access this wayPoint variable that is going to tell the enemy movement script where to go

and we're going to clear that variable, now if this is not the last way point of the system

we're going to select one random way point of our list of next possible way points

and we're going to put this way point on the movement script of the enemy

as it's next way point, the next thing we have to do is to check the state of the enemy to idle

but if this is the first way point of our system we're going to change the state of that enemy

directly to moving, now let's see how the enemy movement script actually works

in the variable we have a reference to the Root of that enemy, a reference to the navMeshAgent component of the enemy

a transform variable to hold the next way point that this enemy is going to move to then we have a

maximum wait time before moving when the enemy reaches a new way point and a boolean variable

that is going to let us know if the enemy is deciding where to go next, this is going to be like a little effect

for our enemies so that when they reach a way point they wait for a bit like if they were deciding where to go next

and then when this maxWaitTime ends they actually move to their next way point

on the initialization of this script we just get the components as usual

the root component and the agent component, now on the Update() of this script, the first thing we have to do is to check

if this enemy is in the movement state, then we check if this enemy has somewhere to go

so if his wayPoint variable is null, then we change this enemy's state to idle

if this enemy has somewhere to go, then we use the agent component to move to the position of that way point

now the next thing this script does is to check if this enemy current state is idle and it does have somewhere to go

and it is not deciding where to go, then this conditional right here first set the deciding boolean to true so

the enemy is deciding where to go then we calculate our waiting time based on our max wait time variable

and we invoke our get moving function with a delay of the waiting time we just calculated

finally, our get moving function changes the state of the unit to moving and sets the deciding variable to false

that's everything the movement system needs to work as you can see our enemies move to the way points

and once they reach the way points they wait a little bit as if they were deciding where to go and then resume their movement

now let's check our enemy spawning system, as you can see we have an enemy spawning object and it spawns enemies in waves of 3

the only thing this enemy spawner object has is our enemy spawner script

in the enemy spawner script the first thing we have is a list of possible enemies that can spawn on this point

then we of course have a time to wait between each wave then we have 2 integers that will help us

count how many orcs have spawned in the current wave and the maximum orcs we will spawn in each wave

then we also have a little waiting time between spawning each enemy and also a variable that will help us

get a little variation between the time of each wave

on the initialization of this script we invoke the SpawnWave() function with a delay of our wave time

and in this spawn wave function the only thing we do is set the wave count to zero, this is how many enemies

have spawned in this wave and we execute the SpawnOrc() function

the first thing we do in the SpawnOrc() function is of course to increment the number of orcs that have been spawned in this wave

then if this number is less or equal to maximum orcs per wave

we select a random orc from our list of orcs to spawn

and we instantiate this new enemy, finally

we invoke this same function with a delay of spawnTime so this is a recursive function that invokes itself

once enough enemies have spawned what we do is to invoke the SpawnWave() function that was the first one we used

with a delay of waitTime plus a little variation that will depend on the waiTimeVariation variable

so the last ability we're going to give our enemies* is the ability to tell other enemies in it's detection zone

that it has detected an Unit, so it can tell all his friends that he has spotted an Unit so that everyone else joins the combat

Let's see this in action, when the first unit comes into this enemy* detection zone

it is going to tell this two enemies*, it is going to alert these two enemies* and this enemy* is going to also alert

this other enemy right here, let's see this happening, the unit comes in the detection zone and everyone gets to combat

this is our enemy alert script, it only has 4 variables, first a reference to the Root script of the enemy

then a transform to keep track of the spotted unit and a vector3 to

have an alert point and a reference to the navMeshAgent component

of the enemy, on the initialization, as usual, we only get the components we need to have

on the Update() the first thing we are going to check is if this enemy is in the combat state

if it is, we are going to do a for each loop with every object in his detection list

if this enemy finds one of our two units in his detection list then it is going to save it's transform in the unit spotted variable

now once we have assigned a transform to our unit spotted variable, then we're going to look for

every other enemy in our detection zone that is not in the combat state

so we can get this same script component in those other enemies and

assign to their alert point variable the position of the unit we have spotted

after that we're going to change that enemy state to the following state

on the enemies, the following state is going to serve as the alert state

now, still in Update() of this script, we're going to check if this enemy is on the following state which is our alert state

if this enemy have been alerted by another enemy we're going to do a for each loop on all the objects

of this detected list, if we find another enemy in the detection list that is not in the combat state

then we're going to communicate that enemy our alert point and we're going to change that enemy state to the following state

you see how this is going? each enemy tells every other that it have been alerted

now if this enemy is far from the alert point position we are going to use the navMeshAgent component to move

near of that alert point and when we get close to that alert point, we're going to change the state of this enemy

to the moving state, and that's it, that's everything we have to do to enable our alert system in our enemies

and that's it, we have seen how to make every single basic mechanic

to make our simple RTS game, so, thanks a lot for watching this video

and if you have any questions leave them in the comments below, good bye =)

hope to see you again soon~

my next unity videos will be about my grad project

but they will be in spanish :P

thanks for watching my first unity tutorials =)

hope they have been helpful to you~

For more infomation >> Unity Tutorial: Enemy AI (Combat, Movement, Spawn, Alert) - Simple RTS [Creating Games! ~ A-9] - Duration: 16:15.

-------------------------------------------

Unity Tutorial: Ranged Attack and Healing - Simple RTS [Creating Games! ~ A-8] - Duration: 7:27.

In the last video we saw how to implement HP bars and floating texts

In this video we're going to see how to make distance attacks with projectiles

And also, let's see, this traitor right here

is going to be doing some healing to our enemies

Lets take a look at the new elements on our scene the units now have a healing particle

like you saw in the intro and also, our units, besides having this same healing particle

now have a ranged attack script

not only the basic attack but also the ranged attack script we also have prefabs for our bulltes

normal bullets to do damage and a healing bullet to heal units

the components of these bullet prefabs are just a mesh filter a mesh renderer and a trail renderer for the effect

they do when they move it's just a visual effect nothing important and we have a bullet script that is going to

determine how these bullets or how these projectiles behave. Let's take a look at some new things we have in our Root script

first we have a reference to the new particle which is our healing particle and in the initialization of

this script is a little more complex, to get the damage particle of the unit we use GetComponentInChildren<>()

but now this object has two child objects that* have particle systems so

to get a second particle which is our heal particle we have to use a new method which is the

transform.Find("NameOfChild") with the name of the object that has the healing particle

and then we use the GetComponent<ParticleSystem>() of that child object

as you can see in the scene the particle system that has the healing particles

is in a game object whose name is "Heals"

the next new thing we have in our Root script is a function to get heals

remember we have TakeDamage(), well we need another function to get heals

now the first thing this function does is to use the heal particles then it makes sure that the HP

does not go over the maximum HP of the unit by using a ternary operator (var = condition ? true : false)

and using the values we have stored in our HP bar, then we update our HP bar

like we did before in GetDamage() and finally we instantiate our floating text

but with a little "+" sign before the healing amount we're going to display

now let's check out our ranged attack script it works pretty much the same than the basic attackscript

but now we need to have a variable to store the bullet prefab and another variable to set the range at

which this unit is able to shoot the bullets, this script follows the same logic as* the basic attack script

but now we have 2 differences, in this step, where we chase our target

we now compare to the range variable instead of the reach variable

so that we get to an attack distance a lot easier because the range is going to always be higher than the reach

the other difference is right here, before we used to deal the damage directly to the unit

now instead of doing that we're going to instantiate a clone of our bullet prefab

once we have this new bullet on the scene we have to tell it 2 things, the damage it is going to deal

and who is it's target, this is our bullet script

on the variable we have, of course, the damage this bullet is going to make, the target of the bullet

and a boolean to know if this bullet is actually going to deal damage or heal it's target

these other 3 variables are going to be used for the movement of the bullet

the first thing we have to do is to check if the target of the bullet still exist because maybe while the bullet was

traveling trough the air something else destroyed it's target and if that is the case the bullet is going to destroy itself

so if that is not the case, the bullet is going to travel to the position of it's target

We're going to do that with a simple MoveTowards() method where we use the

bullet position and the target's position and the velocity of the bullet

multiplied by Time.DeltaTime and we're going to modify this velocity by this bullet aceleration

and we're going to once again modify the acceleration by the force "applied" to this bullet, this is something

extra I like to do when using MoveTowards(), it gives the object, in this case the bullet, a nice

and smooth acceleration the next thign we have to do is to check the distance between the bullet and it's target

if it is really close then it is going to check* the boolean isHeal to know if it is going to use the GetHeals()

or TakeDamage() of the Root script of the target of the bullet

then after it has done this it is going to destroy itself

and that's it, that's everything you have to do to implement distance attacks and also healing

on the next video we're finally going to give our enemies the ability to move around and attack our units

so if you have any questions leave them in the comments below and thank you so much for watching this video :)

Subtitles take so long~~~

This time I tried to do it by bigger chunks

seems to be faster like this

hope you don't mind :D

maybe it is better like this~

bye~ thanks again for watching =)

For more infomation >> Unity Tutorial: Ranged Attack and Healing - Simple RTS [Creating Games! ~ A-8] - Duration: 7:27.

-------------------------------------------

СМЕШАРИКИ. Лепим из пластилина КРОША в новогоднем наряде. Лепка для детей - Duration: 2:05.

For more infomation >> СМЕШАРИКИ. Лепим из пластилина КРОША в новогоднем наряде. Лепка для детей - Duration: 2:05.

-------------------------------------------

LEGO® Batman Movie

For more infomation >> LEGO® Batman Movie

-------------------------------------------

#1 Rated Throwing Set?

For more infomation >> #1 Rated Throwing Set?

-------------------------------------------

Co-workers pay tribute to man who died after SUV plunged off H-1 Freeway - Duration: 0:52.

IT'S BEEN FOUR DAYS SINCE A

DEADLY

CHAIN-REACTION CRASH SENT AN

S-U-V

SPENCER

UEDA OF AIEA DIED AFTER HIS

S-U-V

LANDED ON NIMITZ HIGHWAY BELOW.

HONOR.

THE MEMORIAL BEARS A NOTE FROM

HIS

FORMER CO-WORKERS AT THE HARBORS

RADIO THAT HAS KEPT US SAFE ON

MANY

POLICE SAY UEDA'S S-U-V WAS HIT

BY A

BEFORE HITTING UEDA'S S-U-V --

BUT

THE PEOPLE IN THE FIRST CAR WERE

NOT

HURT.

THE TAXI DRIVER HAS NOT BEEN

For more infomation >> Co-workers pay tribute to man who died after SUV plunged off H-1 Freeway - Duration: 0:52.

-------------------------------------------

'La La Land' Trailer

For more infomation >> 'La La Land' Trailer

-------------------------------------------

Thank You From Spotify

For more infomation >> Thank You From Spotify

-------------------------------------------

정말 맛있는 망고 티라미수 만들기 / How to make really delicious Mango Tiramisu - Duration: 1:53.

For more infomation >> 정말 맛있는 망고 티라미수 만들기 / How to make really delicious Mango Tiramisu - Duration: 1:53.

-------------------------------------------

'La La Land' Movie

For more infomation >> 'La La Land' Movie

-------------------------------------------

Love Rudy Mancuso?

For more infomation >> Love Rudy Mancuso?

-------------------------------------------

How to Choose the Right Bra for daily use - Duration: 2:39.

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

How to Choose the Right Bra for daily use

No comments:

Post a Comment