Thursday 12 June 2014

Prototype - Enemy Spider Robot

It's really hard to find good characters so I will start with free one from Popup Asylum

I wasn't able to import those into Unreal so here you can find package with mesh and animation DOWNLOAD - just copy it to your Blueprints/AI.

Basically the first enemy won't be so effective but it's easy to implement. If you have ideas how I can improve the mechanics feel free to comment!

What we need to do with the spider:
  • Should move to player with animation,
  • Should shoot player using some laser (and use RateOfFire),
  • Player should be able to kill the spider,
  • When spider is dead he should play death anim and maybe some rag doll,
We will be using Anim Notify, Animation Blueprints and modify tasks. 

Move To Player
Right click on Spider Skeletal Mesh and Create -> Animation Blueprint. Name it SpiderAnimBlueprint. 

Create new blueprint and extend from MainAIPawn. Name it SpiderCharacter.
Assign Spider Skeletal Mesh to Mesh component. And use SpiderAnimBlueprint as Anim Blueprint Generated Class.

Open SpiderAnimBlueprint and move into Anim Graph. Right click and select WalkForward animation - connect it into Final Animation Pose. You will see movement now, but it will be rotated. 

Go back to SpiderCharacter and rotate mesh component so it will be forward.

Close everything and open Level Blueprint. Change spawning actors from MainAIPawn to SpiderCharacter.

As you will see you will need to work with rotation, scale and WalkSpeed (from movementcomponent), as well CylinderComponent size to mach the spider size.

Material - fresnel.
You can use Fresnel as I did - it's something like Rim Lighting. 

I will be using Fresnel later to improve graphics quality so you can experiment with it. 


Play Attack Animation
Open SpiderCharacter blueprint and add int variable: SpiderState.

Open SpiderAnimationBlueprint and go to AnimGraph.

Create new block Blend Poses by int. If you right click on it you will see Add Blend Pin - there should be 3 of those.

Create new int variable: SpiderState. Add new animations: Attack and Death and assign them to Blend like here:
Now go to EvengGraph and add Event Blueprint Animation. Get SpiderCharacter and set SpiderState from SpiderCharacter like here:
That's all for AnimationBlueprint, now move into AI_MainPawn and add new input to MyAIAttack. It should be float and name it DeltaTime.

Open SpiderCharacter and add event MyAIAttack right click on that and add super call. 
Thanks to that we will be calling everything that is in AI_MainPawn and after that everything new that's in SpiderCharacter.

Create new float variable AccumulatedDelta. Now we need to use RateOfFire. So create something like this:
Thanks to that we will be firing Print String with RateOfFire. You can close SpiderCharacter for now. 

Create new blueprint extended from AnimNotifyState and name it SpiderAttackNotify. Open it.

You will see 3 functions: Tick, End and Begin. Right click on Tick and Implement Function. We will be calling MyAIAttack from this class like so:
You can close SpiderAttackNotify.

Open SpiderWarior_Attack animation. Right click on Nofifies and add SpiderAttackNotify.
Now move the notify to the place in animation where you want the spider to attack. 
That's all here. Basically Notifies are really nice tool and you should experiment with it a lot. 

Finally open SpiderCharacter and Set SpiderState to 1 right after Event My AI Attack fire. (you should disable all of PrintString at this point only leave one in SpiderCharacter)



Attack Player
Open spider skeletal mesh and create socket named "Spider_Attack" at PA_WarriorWeapon1.

Open SpiderCharacter and create new variable: Beam -> Particle System. Assing P_Electricity_arc particle to it, and disable Auto Activate.

Create Begin Play function and attach Beam to the socket. 
Open SpiderAttackNotify and implement Begin and End. Begin:
End:
So this will activate beam effect and deactivate after notify end.

For now Spider isn't doing any damage, we will do that later when we will have player health bar.


Killing Spider
Will need to implement basic Damage system and we have an problem that we don't have main projectile so it need some refactoring. 

Let's say we want to kill the spider using Pistol. Open Pistol_Projectile and in RailHit function add this:
Be sure that your Min and Max damage aren't 0. 

Now open MainAI_Pawn and add Event Any Damage like here:
This will modify health variable.

Open your blackboard data MainAIData and add Bool variable named IsDead. After that open your Behavior Tree and add one selector in the beginning with Blackboard decorator. (rest of the tree shouldn't be changed)
Now open SpiderCharacter and create Event Any Damage. 
That's all. As always experiment a lot with everything!


Final Result

In next post I will implement controls so it will be easy to shoot. There are couple of problems with Behavior Tree that should be fixed in 4.2.1 - so I won't be moving forward with AI before the issues will be fixed.

No comments:

Post a Comment