Rocket Shooter, an Unreal 4.10/C++ prototype developed by Pedro Cori and I, is a 3rd person multiplayer 3D action shooter.
- Player Controller, Projectile, and Explosion C++ base class definitions, adhering to Unreal Gameplay Framework’s server-client model (replication and RPCs).
- APlayerController (server-only) has a TSubClassOf<AProjectile>, which serves as the prefab to instantiate on the corresponding key-presses. Projectiles are marked to be replicated, along with their movement.
- On detecting a Fire binding key press, the APlayerCharacter instance sends a server RPC, requesting it to start firing projectiles (at regular intervals, until button release).
- APlayerController calculates the trajectory of the projectile by raycasting straight ahead from the camera (effectively the first hit at which the crosshair points) and drawing a vector from the Character’s location to that point.
- Server instantiates a projectile with a rotation corresponding to being aligned to the vector mentioned above, and location being the same as the Instigator‘s (appropriate collision channels have been set in the editor, and Instigator is added to the Collision ignore list).
- AProjectile has these components: TSubClassOf<AExplosion>, USphereComponent and a ProjectileMotion component, and logic that on detection of a collision sends a server RPC to spawn an Explosion instance.
- AExplosion has a USphereComponent that acts as the damage sphere. Exposed UPROPERTYs allow for adjustment of the inner sphere (where damage is always 100%) and the total damage dealt; falloff damage will be calculated based on the BaseDamage value. Apart from calling TakeDamage, it also adds a pseudo-force (called PendingImpulse) into each Character within the sphere of influence, directing radially outward from the centre. Explosions are replicated.
- APlayerController shaves off DeltaSeconds from PendingImpulse each frame, and requests the base class to move the character that much, in the direction of PendingImpulse, each frame, until a nominal value is reached, at which point PendingImpulse is reset to 0.
- Blueprints of Projectile (containing the mesh and sound) and Explosion (particle effect and sound) are created and used. These are local-only, cosmetic effects that do not need RPC execution.
- Splash damage (radial fall-off) and impact impulse (radial pseudo-force) for explosions.
- Raycast-based aiming system: the target is determined by a raycast from camera, and the projectile is launched from player towards it.
- Lobby for server selection, with Steam integration.