Welcome back.
So we have loot, but I'd like our loot to behave a little bit more dynamically when we spawn it.
I'd like it to fly up and pop down, and then hover and rotate and all kinds of really juicy things
that we can add for very little effort.
So in this video, we're going to add a couple more capabilities to our aura effect actor that we can
opt into or out of.
Just keep in mind that this is going to involve the tick function, which means we'll now have a little
bit less optimal code.
Things that don't tick are less expensive than things that do, so keep that in mind.
But of course this is just an option.
Now, I'd like my aura effect actor to be able to rotate and bob up and down and just have tick functionality.
And of course we can disable tick from actors in the blueprint pretty easily.
So we don't have to opt into this for any actor.
But if ticking is enabled, then I want to have some effects.
So in my Aura Effect actor, I'm going to add a couple of things.
I'm going to start by adding some options, some flags that we can turn on or off.
I'm going to have a boolean called be rotates and by default set it to true.
Give it a U property edit anywhere blueprint rewrite going to give full access to this category.
Pick up movement.
Now if we have rotation I want a rotation rate.
So I'm going to make a float called rotation rate and set it to 45 by default and give it full exposure
to blueprints.
Now I'd also like to know if we'd like to bob up and down with sinusoidal movement.
Sinusoidal meaning following a sine wave curve.
And this will be a Boolean be sinusoidal movement.
And I'm going to set this to false by default, because I don't want sinusoidal movement.
In the beginning, when my potion is flying up and falling down, we'll enable this after a short period
of time.
So again, edit anywhere blueprint read right here.
And then I'm going to have a function to start the sinusoidal movement called start sinusoidal movement.
And this will be blueprint callable.
So you function blueprint callable.
And for sine waves there are a couple of parameters we can have.
I can have a float called sine amplitude.
I'm going to set that to one by default.
And I can have a float called sine period.
This can affect the rapidity or speed of bobbing up and down.
And these two can also be added anywhere.
Blueprint.
Read write.
Now, in order to have sinusoidal movement, I'm going to need an initial location that I want full
access to in blueprint.
So I'm going to make an F vector called initial location that I'm going to set right at the beginning
when spawning this thing.
But I'd also like to be able to reset it at any given point in time.
So I'm going to make this exposed as well.
And then finally I'm going to have a private non-exposed variable way down here at the bottom private.
This will be a float called running time initialized to zero.
So running time will keep track as we're updating our sinusoidal movement.
So now we're going to need to tick.
So I'm going to override the tick function in the public section.
So virtualvoid tick takes a float called Delta time override.
And we'll go ahead and generate this function definition.
And we'll also generate the definition for start sinusoidal movement as well.
And in begin play, the first thing I'll do is go ahead and.
Store my initial location.
Where is it?
It's right.
Here.
I'm going to store that initial location right away.
So we'll say initial location equals get actor location.
And in tick we're going to update the time.
The running time.
We're going to say running time plus equals delta time.
But running time could overflow.
And because we're only using this for periodic sinusoidal movement, we're going to reset this to zero
every time we've reached the period, which by the way, are period.
A normal period for the sine wave is typically two pi.
So we might as well just initialize this to about two pi just by default.
6.28318 with a comment that says two times pi.
And then we'll check.
Every time running time exceeds this, we'll set it back to zero.
We'll say if running time is greater than period or sine period.
Running time equals zero.
And in fact, we might as well.
Give this a body there.
Okay, so we're resetting it every time the period is reached.
So now in tick we want to do our sinusoidal movement and start sinusoidal movement is going to set be
sinusoidal movement to true and reset the initial location.
So we're going to reset the initial location to the actor location.
That way we now have the current location.
So when we call start sinusoidal movement which we can call from blueprint.
Then we reset the location and we start doing sinusoidal movement.
And for that I'm going to have a movement function that we can call in tick.
So I'm going to have a void function.
This could even be a private internal function here void pickup.
Or we'll say item movement.
So we can generate this definition.
I don't want it in line.
So I'm going to copy it control X to cut it actually and move it up here next to tick.
And we'll call this right here Item movement.
Now we have a couple of booleans we can check right.
We have B rotates.
So we have B sinusoidal movement.
So we can check those.
So first I'll check b rotates.
So if b rotates then I'm going to make a const f rotator called delta rotation.
And initialize it with zero for pitch and roll.
But for the yaw I'm going to use delta time, which means I need delta time.
I'm going to go ahead and pass that into item movement so item movement can take a float.
Delta time.
So we'll get that passed in and we'll pass in Delta time from tick into item movement.
And I'm going to take delta time and multiply by rotation rate.
So we're scaling it by delta time.
That's going to be for your pitch and roll are zero.
And we can finally take our mesh or effect actor and we can rotate it.
But of course our effect actor doesn't have a mesh does it.
So really we can just set some proxy variable.
And if we have a mesh in the blueprint, well we can use that, right?
We can have a item location and item rotation that we can just set and then use in the blueprint.
So I'm going to have those two.
They'll be blueprint read only.
So we're going to have an F vector called calculated location u property blueprint read only.
And we'll have an F rotator calculated rotation with a u property.
Blueprint read only.
Now, what we can do with these is here in begin play.
First of all, we can initialize these.
And if we're going to initialize initial location and start sinusoidal movement we'll initialize it
there as well.
So what we'll do is we'll say calculated location equals initial location here.
And calculated rotation equals get actor rotation.
Like so now in item movement, delta rotation is calculated.
And what we're going to do is just add this to our calculated rotation.
So we're going to take calculated rotation.
And we'll use you Kismet math library.
Combine rotators or compose rotators is what I'm looking for.
So we'll take first calculated rotation and we'll compose it with delta rotation.
And that's the same effect as adding them together.
So now our calculated rotation will be changing according to our rotation rate.
Now for sinusoidal movement.
If be sinusoidal movement then we have an initial location and we have our running time.
So we need to calculate the sine of the running time.
We can do a const float.
We can call this sine.
And we're going to take f math sine of running time.
Now if we want to transform this we can transform it with the amplitude using sine amplitude here multiplying
it.
And if we want to affect the period we multiply running time by sine period.
Now, mathematically, the period is actually two pi divided by this value.
So this isn't actually the sign period.
It's actually a sign period constant.
So we can call this sign period constant.
And let's just set it to one for now and I'll show you how this works.
But we're going to say sign period.
Constant equals one.
So constant there and then we want to reset our running time every period and the sign period we can
calculate here const float sign period.
And that's going to be two times pi.
We can use two times the constant pi that's built into the engine divided by sign period constant.
So we really want to reset running time every sign period which is calculated by this formula.
As long as we're using it properly here by multiplying by running time.
So sign period is two pi divided by the sign constant.
Sign constant is here.
So now that we have the sign, we can set our calculated location by adding this value to the z.
So we can say calculated location equals.
And we can take initial location.
And we can add the f vector with zero for x and y and z can be sign.
So now we have calculated rotation and location.
And we can set these on the mesh for whatever mesh we're using.
And just like I have start sinusoidal movement.
Where is it?
Start sinusoidal movement.
I'd also like a start rotation.
And really just set B rotates to false by default because we're going to want the accurate rotation.
We're setting the rotation when we spawn this thing.
Right.
So I'm going to have another blueprint callable function as well.
And we'll call this start rotation.
And start rotation is going to be similar to start sinusoidal movement.
It's going to set be rotates to true and set our calculated rotation equal to get actor rotation.
And while we're at it here we're going to set our calculated location as well to initial location.
And start sinusoidal movement.
So it's reset there.
Okay.
Let's compile and see how these work by calling start sinusoidal movement and start rotation and using
those calculated values to set our location and rotation for these pickups.
So I can go into my potions and open BP health potion for example.
And we can go into event begin play.
And we can call start sinusoidal movement.
And we can call.
Start rotation.
And in tech, which by the way, in or effect actor tick is false.
But we can enable it here.
We can override it in the blueprint by searching for tick.
Looks like start with tick enabled is already on overriding that.
So here's event tick.
I'm going to bring it over and I'm going to call set actor location.
And I'm going to get calculated.
Location.
And I'm going to call set actor rotation.
And get calculated rotation.
So compiling that, I'm going to spawn some of these pickups.
Looks like I need to load in.
Of course.
Through the load menu.
Starting off with my spouse.
Okay, so we got some rotation.
We have some actors rotating and some not.
Actually we only did this for the health potion, so that's expected.
But I'm going to detach and come in close and see if we can see any sinusoidal movement.
And sure enough we do have some slow bobbing behavior, but that amplitude is very low.
Now, I don't want to have to go in and do this for all of my pickups.
So an easy way to achieve this would be either to set the actor location and rotation in C plus plus,
or to create a base pickup that all of my potions and crystals can inherit from.
Either one is totally fine, but before doing that, I'm going to change my sine amplitude.
I'm going to try a value of eight and see if that's a little bit more noticeable.
So there's my potions.
They're bobbing up and down.
That's looking good.
Let's actually increase that sign period as well.
To four.
Might be a little too fast, but we can try that.
Okay, I like that better.
Actually.
I'm happy with these values.
So I'm going to make a base pickup class that our pickups can inherit from.
And they can still have their own overrides in their own blueprints.
But I'm going to go to actor and just make a blueprint class here based on our effect actor.
That's what these are all based on.
And I'm going to call this VP pickup underscore base.
And in pickup underscore base I'm going to take my event begin play.
And we'll just for now start sinusoidal movement and rotation.
And I don't need actor begin overlap.
But I do want tick.
And I'm going to take these.
Control X to cut them and paste them here for tick.
And I don't need those nodes in health potion anymore.
But what I want now is to base my health potion on pickup base.
But before we do, let's take a look at our class settings.
And notice we have instant gameplay effect.
Potion heal.
Do not apply.
None.
Do not apply.
None.
Do not apply.
Remove on and overlap.
Act A level one.
Easy to remember.
Now if we go to class settings and change this to BP pickup base.
Now, if we go back to class defaults, we can check to make sure those are the same.
And they are.
Great.
Now if we go into pickup base we can set those sign properties to better values.
I think sign amplitude was eight, sign period constant was four.
And now anything that derives from pickup base can inherit that.
And that's going to be our mana potion as well.
Class settings.
We're going to search for BP pickup base.
We'll go to our crystals health crystal class settings.
Set it to BP Pickup base.
And mana crystal BP pickup base.
Now.
After saving, we should be able to see all of them bobbing up and down.
And we have those nice bobbing sinusoidal movements and they look really nice and cool.
All right.
So that's going to wrap it up for this video.
I noticed one issue though when moving when I clicked on something say outside of where I think I want
to go, like on the rails or something.
I think that auto running is never setting back to false.
That's something that I need to fix in my player controller.
And I think I remember in our player controller, in one of our recent changes we made right here in
ability input tag pressed, we moved some things into is valid here.
We moved setting our targeting status based on this actor and setting auto running to false when ability
input tag is pressed.
However, auto running should be false regardless of whether this actor is valid or not.
So that's going to cause issues unless we go ahead and put this auto running outside the if check here,
make sure we always set it to false as long as we're pressing the left mouse button here, we always
want to set that to false.
So that's going to fix that issue okay.
So next time we compile that will be fixed.
Excellent job.
And I'll see you in the next video.