My stationary shooter needs to have enemy that is able to walk on walls. Thanks to that player will be forced to aim on walls / ceilings. Enemy specs:
- Low health, will explode and do damage to others,
- Possibility to move on walls / ceilings,
- Do damage over time,
- As always – done in blueprints without C++ code,
<strong>This Tutorial has been created using Unreal Engine 4.8.2</strong>.
Make sure you are working on the same version of the engine.
This spider will have some restrictions:
- Can’t extend from Character because of CharacterMovement component which is causing issues when walking on walls. He need to extend from Actor and I would need to implement TakeDamage strictly for him,
- He can’t use navigation and pathfinding. He will just move forward and if near player try to do damage over time. This restriction is harsh for gameplay but I don’t want to implement pro spider in C++,
- He won’t use IK for his legs. He is to small and player won’t see IK working. I will definitely create spider boss enemy, much bigger with legs driven by IK and movement using physics – this will be explained in later tutorial,
- Your mesh collisions need to be prepared correctly. What I’m doing is go to static mesh and select: Collision Complexity: Use Complex Collision as Simple. This can cause issues with movement. Basically graphics artist need to prepare good collision meshes when using Spider,
I have found C++ implementation of exactly the same thing I’m doing here. If you are more advanced UE4 user you can read his implementation.
Create new blueprint extending from Actor.
This part is critical if you change rotation of something it won’t work! Be careful when creating hierarchy.
Scene Component – Root:
Arrow Component – TraceDown:
Arrow Component – TraceDown_Second:
Arrow Component – TraceBack:
Arrow Component – TraceForward:
Those are critical because they are used to check walls and they are driving movement.
Spring Arm Component – SpringArm:
Spring Arm is used to interpolate mesh location and rotation because location / rotation of this actor is changing in tick. You could get weird results when tracing when it’s interpolating position/rotation.
Skel Mesh Component – SpiderMesh.
- SkelMesh: SpiderWarior_Skel,
- Anim Blueprint: Spider_AnimBP, (which you don’t have yet)
- Collision Presets: NoCollision,
Particle System Component – FX_Beam.
- Template: P_electricity_arc which can be found in Shooter Example. Later in this tutorial I will update this particle system.
- AutoActivate: False,
Box Component – Box.
- Location: (X=0.000000,Y=0.000000,Z=27.094894)
- Scale: (X=1.000000,Y=1.000000,Z=0.471904)
It will be used for collisions with bullets.
Now implement I_TakeDamage interface for this Actor.
Open graph and create variables:
- DeltaTime (float),
- MinDistanceToPlayer (float),
- isDead (bool),
- Damage (float, default: 2),
- Health (float, default: 25),
And now functions:
IsNearPlayer – one output isNear (bool) – pure function
ChangeLocation – input: HitResult (hit result)
This function is critical for generating spider location and rotation. I would like to thanks Alexander Tsekhansky and Krystian Komisarek for big help with creating this!
Now let’s go to Event Graph and create some events.
MoveForward (custom event)
Spider will move always forward. You could replace this with spline movement or make path. This is the simplest way for me.
RotateToPlayer (custom event)
And now the most important event – Tick where everything is happening.
It have 4 traces – for easier reading separated screens:
So basically spider is checking if wall is in front of him – if yes move toward the wall. He is checking if floor is above him if not find next rotation in ChangeLocation function.
Spider Attacking Player
Currently Spider will stop near player and play Attack animation.
Create new Blueprint extending from AnimNotifyState. Name it SpiderTimeAttack.
Override Received Notify Begin:
This is activating beam particle and select end point for beam.
Override Notify End:
To stop the particle.
Override Notify Tick:
This is actually dealing damage to player.
Now go to Attack animation and add this notify.
I have changed some things in beam particle.
- Beam target is “User Set”,
- Beam Data -> Max Beam Count: 2,
And I have activated light_flickering emitter which is performance killer but it’s looking nice. You need to assign this material into light_fickering:
And Light parameters:
Still in the light_fickering emitter:
- Spawn -> Screen Alignment: PSA Facing Camera Position,
- Initial Size -> 30, 30, 30,
- Initial Color -> start Alpha -> Constant: 1,
And that’s all for the particle!
Basically spider should be easy to kill and should explode after kill.
Create new Blueprint extending from Actor named SmallSpider_Explosion. If you downloaded spider you should get sliced spider static meshes. Add them to this blueprint.
And here’s theirs properties:
- Add Radial Force Component with Radius: 50,
- Add Box Component. Location: (X=0.000000,Y=0.000015,Z=12.651192) Scale: (X=1.000000,Y=1.000000,Z=0.359557) this will be the random place where radial force will be placed,
- Add Particle System Component: P_Grenade_Explosion which can be found in Shooter Example.
Open Graph and create Explode function:
And Begin Play:
So basically when this actor will be spawned all parts will use physics and radial force will make the “explosion”
Dealing Damage to Spider
Last thing is to implement Take Damage events from interface on Spider Blueprint.
This will spawn explosion and update health.
This tutorial is bad example of Object Oriented Programming. We cannot extend from BP_BaseEnemy because CharacterMovement component is causing issues with spider movement, and we needed to copy lot of functions we had in BP_BaseEnemy. Using OOP is not always good approach.
Implementing game is taking time but writing about it is taking much more effort!