Overwatch Genji’s Ability in UE4

Jun 16, 2016·
Akbolat Sadvakassov
Akbolat Sadvakassov
· 3 min read

The next ability that I love in Overwatch is Genji’s Deflect, that can deflect everything in game, that wants kill you 🙂

Before we start, we need take a look at bullet types. I’ll be brief.

Projectile vs. Instant hit.

Almost all games use two bullet types – Projectile and InstantHit. Difference between them is that first supports gravitation, velocity, direction of the wind, i.e. as in the real life, but it make its expensive from performance point of view, especially in Online games. In main case, Projectiles – are rockets, grenades, arrows, etc. IstantHit, or also named as TraceHit, is just a LineTrace, that doesn’t supports gravity, velocity, etc. It strictly shoots from muzzle of weapon. It uses, for example, in CS, CoD games.

There is a video on YouTube, that shows What Genji can and can’t DEFLECT.

Logic

Editor version 4.11.2. Tutorial based on FirstPersonTemplate.

How did I implement it? By activation ability, we create a flat box collision in front of character, and when Projectile or IstantHit(Line-Trace) hit that box collision, we define it, then if it was Projectile spawn it, or if it was InstantHit shoot LineTrace. I’m not sure about InstantHit logic, but it works well. If you have any ideas, tell us in the comments.

Open FirstPersonCharacter -> Viewport, add BoxCollision and bind it to FirstPersonCamera with next Location and Scale settings. Then set Projectile in Collision Presets, it’ll make BoxCollision react only to projectiles.

You should get the following:

Let’s start with Projectile. Open EventGraph and create OnComponentHit event, select BoxCollision, in the Details/Events panel click at “+” near OnComponentHit. Then make the following:

OnComponentHit – event, that activates, when BoxCollision has been hit. Its parameter – OtherActor, gives an info about actor that hit BoxCollision. We convert(GetClass) and Spawn(SpawnActor) it with new Location and Rotation values in the direction of sight.

Now InstantHit. Create a custom event and name it – DeflectTrace:

Multiplying by 2000, it’s the length of the trace-line. 1 unit = 1 cm.

Multiplying by 2000, it’s the length of the trace-line. 1 unit = 1 cm.

DeflectTrace shoots LineTraceByChannel, in Start parameter gets BoxCollision’s location coordinates, in End parameter gets coordinates of straight forward Vector(GetForwardVector) summed with BoxCollision’s.

Test bot

To simulate shots in the scene, we’ll create a bot, that shoots Projectile and InstantHit. Create new Actor Blueprint, name it AutoShootingMachine. In the Components panel add mesh, for example Sphere, and Arrow for navigation. Turn off Sphere’s collision(Look at picture).

Place it to the scene.

Shoots in Arrow’s direction

Shoots in Arrow’s direction

In EventGraph, create an alternative EventTick,

Sequence-Then 1 – shoots LineTrace

I’m not sure about this implementation, but it works

I’m not sure about this implementation, but it works

LineTrace with random End-coordinates. If it hits anything, we cast to FirstPersonCharacter and if cast was successful call custom event DeflectTrace.

Sequence-Then 2 – spawns Projectile

Set FirstPersonProjectile in Class parameter

Set FirstPersonProjectile in Class parameter

And the last thing, open FirstPersonProjectile

Add DestroyActor to False(Branch).

That’s all implementation. Next are binding and cooldown.

Binding to Key

In FirstPersonCharacter, create boolean isDeflectAvailable and function Reloading:

At the beginning of the game, we’ll turn off collision

New Response = Ignore

New Response = Ignore

And when we press “E“, ability activates for two seconds(New Response = Block), then it turns off for 16 seconds until it reloads(SetTimerByFunctionName) as in the original game.

In result you’ll get:


It’s a mirror from WebArchive