Ranged
Module PulseCombatRanged (depends on PulseCombat). A ranged attack is a gameplay ability that shoots flying projectiles or hitscan traces. Bows, guns, shotguns, grenades and spells use the same ability with different data.
Setup
- Make the shooter a combatant (see Combat).
- Create a Pulse Projectile data asset (
UPulseProjectileDefinition, Primary Asset TypePulseProjectile) or fillInlineProjectileon the ability. - Give
UPulseRangedAttackAbility(or a Blueprint child) with the projectile definition as source object of the spec, or set Projectile on the ability. - Press the ability input to shoot. With
bCanChargethe shot leaves on release.
Projectile parameters (FPulseProjectileParams)
| Group | Fields |
|---|---|
| Flight | Speed, GravityScale (0 straight, 1 arc), Lifetime, CollisionRadius, HitscanRange |
| Damage | Damage, DamageType, DamageTags (Pulse.Combat.Damage.Ranged is always added), bCanCrit, DamageEffect, HitEffects |
| Piercing | MaxTargets: combatants hit before the projectile stops (1 = no piercing). A blocking hit on an actor that takes damage (health set or IPulseDamageable, e.g. a wall of a building) is a direct hit, too. |
| Area | AreaRadius (0 = none), AreaMultiplier at the center, AreaMinMultiplier at the edge. Area damage at the impact skips the targets hit directly and carries Pulse.Combat.Damage.Area. |
| Look | Mesh, MeshScale (empty mesh = small sphere), ImpactCue (gameplay cue at the impact) |
HitEffects are the same instanced structs as for melee and run on direct hits.
The ability
| Property | Meaning |
|---|---|
bHitscan | Trace instead of a projectile |
ShotsPerAttack, SpreadDegrees | Pellets and their spread cone. The spread is seeded per shot, so it is the same on every machine. |
MuzzleSocket / MuzzleOffset | Start of the shots |
MaxAimDistance | How far the camera aim trace looks for the aim point |
bCanCharge, MaxChargeTime, FullChargeDamageMultiplier, FullChargeSpeedMultiplier | Hold to charge |
MaxOriginError, MaxAimDeviation | Server check of client shots (0 = not checked) |
OriginTolerance, OriginLateralTolerance | How far the server lets a client’s origin sit from its muzzle: along the aim (50 cm), across it (12 cm) |
Fire rate is a cooldown effect; ammunition and stamina or mana are attack costs (AttackCosts, Pulse costs such as Items and Attribute, or the costs of the weapon that granted the ability, see Combat and inventory). When the server cannot pay them after the check passed (two costs that each see the same arrows, the second payment fails and is rolled back), CommitAbility fails and the attack ends cancelled without a shot. On Fired is a Blueprint hook on the authority. APulseProjectile can be subclassed (set ProjectileClass in the definition) for own visuals or homing.
Extending the attack in C++
FireShots (authority) runs one attack in fixed steps, so a subclass (for example a shooter add-on) can replace one step and keep the rest:
MakeShots(Direction, Seed, OutShots)(virtual, const): the shots of the attack asFPulseRangedShot(direction and index). The default makesShotsPerAttackshots inside theSpreadDegreescone from one seed per attack with the pure functionPulse::Combat::Ranged::MakeSpreadShots. Override it for recoil, fixed pellet patterns or bursts.FireShot(Origin, Shot, DamageMultiplier, SpeedMultiplier)(virtual, protected): fires one shot, a hitscan trace (FireHitscan, protected as well) or a projectile throughAPulseProjectile::SpawnProjectile. The multipliers come from the charge.OnShotFiredNative(native multicast on the ability instance): broadcast on the authority after eachFireShotwith the ability, the origin, the shot and the seconds charged, for tracers, muzzle effects or statistics in C++.- Then the debug timeline event and On Fired once per attack, as before.
Flight path
Pulse::Combat::Ranged::SampleProjectileTrajectory(Params, Origin, Direction, OutPoints, WorldGravityZ, Step, SpeedMultiplier) (Ranged/PulseTrajectory.h) samples the path of a projectile without a world, for previews in editors and tests: points (FPulseTrajectoryPoint: Time, Location, Velocity) every Step seconds from Speed (times the speed multiplier of a charge), GravityScale times the world gravity (default -980) and Lifetime, the last point exactly at the end of the lifetime. APulseProjectile has no drag, so the path matches the projectile movement until the first hit; collisions are not checked. SampleTrajectory(Origin, Velocity, GravityZ, MaxTime, Step, OutPoints) is the same for any start velocity. A path has at most MaxTrajectoryPoints (4096) points; a smaller step is made larger.
Projectiles in the editor
Projectile definitions open in the config workshop of the Pulse Editor Kit with the preview Flight of PulseGameplay:
- Flight path: the path of
SampleProjectileTrajectoryfrom the side (distance on the ground, height above the muzzle) with the ground at the height of the muzzle. The view fits the path with a margin, each axis with its own scale (a flat shot fills the plot), and both axes carry marks and labels in metres. Angle (degrees above the ground), Speed x (a charged shot) and World gravity Z change the shot; the line below names range, flight time, the highest point and where the path ends. Collisions are not checked. - Damage: the damage calculator with the damage, type, crit and tags of the projectile and
Pulse.Combat.Damage.Ranged, a column per difficulty level (see Damage calculator in the editor). - Where used: ranged abilities, weapons and other assets that name the projectile.
The side view comes from pure functions (Pulse::Combat::Editor::MakeShotDirection, MakeSideView, FitPlotBounds, ChooseAxisStep, MakeAxisTicks, MapToPlot, FormatAxisLabel). Spec: PulseGameplay.Editor.CombatWorkshop.
Aiming
- Players: the shot goes towards the attack target (lock-on or soft target) or along the camera to the point the camera looks at. A client sends origin, direction and charge as target data; the server checks the origin against its muzzle (
MaxOriginError) and the direction against the pawn’s aim rotation (MaxAimDeviation) and rejects implausible shots with a log warning. Target data with NaN or Inf fails its network serialization and is refused by the checks as well (ValidateAim,ClampShotOrigin,ClampChargeTime). Both checks need a pawn whose movement and rotation reach the server (e.g. Character Movement); set them to 0 for pawns that move only locally. The charge the client sends counts only as long as the server saw it: the server remembers when it activated the shot and clamps the charge to the time since then plusChargeTimeTolerance(0.15 s), so a tap never fires a full charge. The shot then starts at the client’s origin clamped around the server’s muzzle by direction: along the shot (the client’s direction, once it passed the check against the server’s aim) byOriginTolerance(50 cm, a muzzle that lags behind or runs ahead with latency), across it byOriginLateralTolerance(12 cm), so an origin is never lifted over cover or moved around a corner. The split follows the shot, not the server’s aim: split along the aim, an origin 50 cm ahead would sit up to 29 cm beside the line of a shot turned byMaxAimDeviation(35 degrees), and both lines of sight could run along a wall past its edge; along the shot, the line from the server’s muzzle covers the part it skips. It only fires when the lines from the shooter’s eyes and from the server’s muzzle to that origin are free (Pulse::Combat::Ranged::ResolveShotOrigin, shared with add-ons such as PulseCombatShooter): an origin or muzzle behind a wall or over cover never fires. Hitscan needs no extra line from the eyes to the impact: the origin stays within a few centimetres of the server’s muzzle, which both lines see, so a client gains no view the server’s own shot from that muzzle would not have. - AI and scripts: activate the ability on the server with the target in the event data,
EventMagnitude= charge seconds.EventMagnitudecounts only where the shooter is locally controlled (AI, the listen host, standalone): the machine that shoots wrote the event data. The server copy of a remote player’s shot never takes a charge from the activation: its prediction key and event data come from the client, and a client can send a key that claims the server started the shot. To give a remote player’s pawn a charged shot, the server hands the charge over withPulse::Combat::Ranged::TriggerChargedShot(AbilitySystem, Handle, EventData): it sets the charge on the ability’s primary instance right before the activation, and the pawn shoots at once on the server, from its muzzle along its aim on the server (or at the event Target), without waiting for the client. (A server initiated activation of a locally predicted ability is never run by the owning client, andTriggerAbilityFromGameplayEventrefuses it on a pawn that is not locally controlled; the call activates with a server initiated key of the server’s own, which the client only confirms.) A script activates it like this:
FGameplayEventData data;
data.Target = Enemy;
Pulse::Combat::PressAbilityInput(AbilitySystem, UPulseRangedAttackAbility::StaticClass(), &data);
Multiplayer
Projectiles are spawned on the authority and replicate (parameters once, at spawn); clients only see them. Damage, piercing and area damage happen on the authority. Hitscan shots are traced on the authority.
Cheats
| Command | Does |
|---|---|
PulseCombatGiveRanged [charge\|hitscan\|grenade\|asset path] | Gives a ranged ability (default: straight projectile, 15 damage) |
PulseCombatFire [release] | Presses the ranged attack (release releases a charge) |
PulseCombatFireOffset <x> <y> <z> | Testing the server’s origin checks: the client’s shots carry their origin moved by the offset (0 0 0 ends it) |
PulseCombatSpawnTurret | Spawns an enemy turret that shoots at the nearest player every two seconds (tests the server path) |