/ Unreal Engine 4

Trump Cannon

Whereas Bat & Ball just reused the Unreal Engine VR template, a bit more work went into this one.

The destructible wall was simple, owing to the Apex plugin. There's so much good stuff in this engine.

The trickiest part was getting usable values from the wheels.

One pitches the cannon up and down, the other rotates it. There are two parts to the function.

First I need to rotate the wheel, depending on where the hand is relative to the wheel. That's straightforward enough by creating a rotator from the difference vector.

Second, I need the wheel to calculate a value that accumulates indefinitely. The angle of the wheel is constrained to -180 ... +180. If I used that the cannon would raise to a point, and reset to where it was and start again.

I needed a linear value that accumulates indefinitely as I keep rotating the weel. The trick was to compare the signs of the current and previous angle, and if they differ, it means the wheel is about to complete a rotation. So we ignore the difference in the angles at that point.

I'm sure this is a common problem that a lot of devs bump up against, here's how I solved it.


It takes the value from the Z (Yaw). An "axis of rotation" variable or similar would be useful to make this function more reusable.



App and web developer, getting into game dev. Used to art direct films, currently a specialist technician and associate lecturer at Central Saint Martins.

Read More