Partial class that handles the dong weapon's attack modes: held-in-hand aim with mouse-driven steering, the momentum follow-through, tip-speed crack detection, the helicopter spin with its hover and release throw, and the three-tap whip combo ending in an overhead slam with marching shockwaves. All damage goes through Rampage shockwaves, LineBlast and controller kicks.
using System;
// The dong, on Attack1: taken in hand and driven with the mouse, wound up into a helicopter, or
// tapped through the whip combo. See DongWeapon.cs for the whole picture.
public sealed partial class DongWeapon
{
// ---- Aim and whip (hold left, move the mouse) ----
/// <summary>Degrees the dong's aim moves per degree the mouse would have turned the camera.</summary>
[Property, Group( "Aim" )] public float AimSensitivity { get; set; } = 1.7f;
/// <summary>How hard the hand pulls the chain toward where the mouse has it (the spring; low is heavy and late).</summary>
[Property, Group( "Aim" )] public float AimStrength { get; set; } = 130f;
/// <summary>A fast mouse pulls harder: this much more at <see cref="FlickSpeed"/> degrees a second and beyond. That is the crack.</summary>
[Property, Group( "Aim" )] public float FlickBoost { get; set; } = 1.6f;
[Property, Group( "Aim" )] public float FlickSpeed { get; set; } = 420f;
[Property, Group( "Aim" )] public float AimPower { get; set; } = 1f;
/// <summary>How far down and how far up and over the aim can go, in degrees from level.</summary>
[Property, Group( "Aim" )] public float AimLowest { get; set; } = -35f;
[Property, Group( "Aim" )] public float AimHighest { get; set; } = 150f;
/// <summary>Left released this soon, with the mouse moved less than this many degrees, was a tap: the combo.</summary>
[Property, Group( "Aim" )] public float TapSeconds { get; set; } = 0.2f;
[Property, Group( "Aim" )] public float TapTravel { get; set; } = 12f;
/// <summary>Seconds it is left entirely to its own momentum after being let go.</summary>
[Property, Group( "Aim" )] public float FollowSeconds { get; set; } = 0.7f;
[Property, Group( "Aim" )] public float AimSlow { get; set; } = 0.8f;
// ---- The crack ----
/// <summary>Tip speed at which it cracks, in inches a second at the lizard's ordinary size.</summary>
[Property, Group( "Crack" )] public float CrackSpeed { get; set; } = 430f;
/// <summary>The crack's shockwave: radius as a share of the reach, and speed.</summary>
[Property, Group( "Crack" )] public float CrackRadius { get; set; } = 0.4f;
[Property, Group( "Crack" )] public float CrackShock { get; set; } = 900f;
/// <summary>For a moment after a crack every hit is this much harder.</summary>
[Property, Group( "Crack" )] public float CrackBonus { get; set; } = 1.5f;
// ---- Helicopter ----
/// <summary>Circling the mouse this many times round winds an aimed dong up into a spin.</summary>
[Property, Group( "Helicopter" )] public float WindToSpin { get; set; } = 1.2f;
/// <summary>Degrees a second it starts at, and the most it can reach.</summary>
[Property, Group( "Helicopter" )] public float SpinStart { get; set; } = 220f;
[Property, Group( "Helicopter" )] public float SpinMax { get; set; } = 900f;
/// <summary>Degrees a second gained each second Run is held, and by each full circle of the mouse.</summary>
[Property, Group( "Helicopter" )] public float SpinPump { get; set; } = 210f;
[Property, Group( "Helicopter" )] public float SpinPerRev { get; set; } = 170f;
/// <summary>Share of its speed it loses each second by itself: momentum is kept, but not for ever.</summary>
[Property, Group( "Helicopter" )] public float SpinFriction { get; set; } = 0.12f;
[Property, Group( "Helicopter" )] public float SpinStrength { get; set; } = 420f;
[Property, Group( "Helicopter" )] public float SpinPower { get; set; } = 0.9f;
/// <summary>How much longer it stretches at full speed (the ring it hits widens).</summary>
[Property, Group( "Helicopter" )] public float SpinStretch { get; set; } = 0.35f;
[Property, Group( "Helicopter" )] public float SpinTilt { get; set; } = 4f;
[Property, Group( "Helicopter" )] public float HeliTilt { get; set; } = 17f;
[Property, Group( "Helicopter" )] public float SpinSlow { get; set; } = 0.7f;
/// <summary>How much of the spin turns the giant's own body round with it.</summary>
[Property, Group( "Helicopter" )] public float SpinBodyShare { get; set; } = 0.3f;
/// <summary>Wound up past this (0 to 1) it lifts: a hop (a share of the jump), then this share of gravity carried for a few seconds.</summary>
[Property, Group( "Helicopter" )] public float HoverAt { get; set; } = 0.8f;
[Property, Group( "Helicopter" )] public float HoverHop { get; set; } = 0.5f;
[Property, Group( "Helicopter" )] public float HoverLift { get; set; } = 1.05f;
[Property, Group( "Helicopter" )] public float HoverRise { get; set; } = 90f;
[Property, Group( "Helicopter" )] public float HoverSeconds { get; set; } = 2.6f;
/// <summary>The release: how long the throw takes, how hard, and what the line it is thrown along does (damage at full spin, times might).</summary>
[Property, Group( "Helicopter" )] public float ReleaseSeconds { get; set; } = 0.6f;
[Property, Group( "Helicopter" )] public float ReleaseStrength { get; set; } = 380f;
[Property, Group( "Helicopter" )] public float ReleaseDamage { get; set; } = 1500f;
// ---- Combo (tap left) ----
[Property, Group( "Combo" )] public float WhipSeconds { get; set; } = 0.5f;
/// <summary>How hard the body throws it (the spring toward the swing's line).</summary>
[Property, Group( "Combo" )] public float WhipStrength { get; set; } = 420f;
[Property, Group( "Combo" )] public float WhipPower { get; set; } = 1f;
[Property, Group( "Combo" )] public float SlamPower { get; set; } = 1.8f;
/// <summary>Seconds after a whip in which the next tap carries the combo on.</summary>
[Property, Group( "Combo" )] public float ComboWindow { get; set; } = 1f;
/// <summary>Seconds after the second whip in which a right click is the clap.</summary>
[Property, Group( "Combo" )] public float ClapWindow { get; set; } = 0.5f;
[Property, Group( "Combo" )] public float FinisherRest { get; set; } = 0.4f;
/// <summary>The step forward into each whip, in inches at the lizard's ordinary size.</summary>
[Property, Group( "Combo" )] public float WhipLunge { get; set; } = 60f;
/// <summary>The overhead slam's line: damage (times might), how hard what is under it is popped up and shoved along, and its width beyond the dong's own.</summary>
[Property, Group( "Combo" )] public float SlamDamage { get; set; } = 700f;
[Property, Group( "Combo" )] public float SlamPop { get; set; } = 1100f;
[Property, Group( "Combo" )] public float SlamPush { get; set; } = 500f;
[Property, Group( "Combo" )] public float SlamWidth { get; set; } = 0.12f;
/// <summary>Shockwave where it lands: radius as a share of the reach, and speed.</summary>
[Property, Group( "Combo" )] public float SlamShock { get; set; } = 0.8f;
[Property, Group( "Combo" )] public float SlamShockSpeed { get; set; } = 1200f;
/// <summary>Height of the little hop into the slam, in inches at the lizard's ordinary size.</summary>
[Property, Group( "Combo" )] public float HopHeight { get; set; } = 10f;
/// <summary>The cracked street: seconds between the shockwaves that march away.</summary>
[Property, Group( "Combo" )] public float CrackInterval { get; set; } = 0.09f;
// Aim.
float _dongBaseYaw, _aimYawOff, _aimElev, _mouseTravel, _pressAt, _flick;
float _wind, _lastMx, _lastMy;
bool _cracked;
float _nextCrack, _crackBonusUntil;
// Helicopter.
float _spinRate, _spinAngle, _spinSign = 1f, _spinTurned, _releaseSpin, _hover, _nextHop, _fallSpeed;
// Combo.
float _aimYaw;
int _stage, _whipIndex, _combo;
float _comboUntil, _clapUntil;
bool _buffered, _slamLanded, _impactDone;
// The cracked street, marching away.
int _crackLeft;
float _crackNext, _crackRadius, _crackSpeed;
Vector3 _crackAt, _crackStep;
static float YawOf( Vector3 v ) => MathF.Atan2( v.y, v.x ) * (180f / MathF.PI);
/// <summary>The clap is on offer: the second whip has cracked, or has just finished, or the third is only just going up.</summary>
bool ClapOpen => _joint == Joint.None && _balls == BallMode.Hang
&& ((_dong == DongMode.Whip && _whipIndex == 1 && _stage >= 2) || Time.Now < _clapUntil || (_dong == DongMode.Whip && _whipIndex >= 2 && _stage == 0));
Angles UpdateDong( float dt, ref float factor, ref WeaponHint lit )
{
switch ( _dong )
{
case DongMode.Aim: lit |= WeaponHint.Aim; factor *= AimSlow; return UpdateAim( dt );
case DongMode.Follow: return UpdateFollow();
case DongMode.Whip: lit |= WeaponHint.Combo; factor *= 0.5f; return UpdateWhip();
case DongMode.Spin: lit |= WeaponHint.Spin; factor *= SpinSlow; return UpdateSpin( dt );
case DongMode.Release: lit |= WeaponHint.Spin; factor *= 0.3f; return UpdateRelease( dt );
}
// Carried: it trails, and is mostly left to its own weight, so it drags, bounces and slaps
// the ground as the giant walks.
TrailDong();
_power = DragPower;
_knock = 0.6f;
_holdLook = false;
Combo = 0;
DongState = HookedName.Length > 0 ? "HOOKED: " + HookedName : "DRAGGING";
return default;
}
// AIM: the rope in the hand. While left is held the mouse moves the place the dong is being
// pulled toward, and the chain follows it with all its weight.
void StartAim()
{
_dong = DongMode.Aim;
_dongT = 0f;
_pressAt = Time.Now;
_mouseTravel = 0f;
_flick = 0f;
_wind = 0f;
_lastMx = _lastMy = 0f;
_holdLook = true;
_dongBaseYaw = _controller.Look.yaw;
// Taken up where it lies, so nothing jumps: the aim starts along the dong as it is now.
var lie = _rig.DongTip - _rig.DongRoot;
float flat = lie.WithZ( 0f ).Length;
_aimYawOff = flat > 1f ? Wrap180( YawOf( lie ) - _dongBaseYaw ) : 180f;
_aimElev = Math.Clamp( MathF.Atan2( lie.z, MathF.Max( flat, 0.01f ) ) * (180f / MathF.PI), AimLowest, 60f );
}
/// <summary>
/// What the mouse did this frame, as the controller would have read it: degrees to the right and
/// degrees up. Also keeps count of how far round it has circled (<see cref="_wind"/>, in radians,
/// signed): the angle between each movement and the last, added up. A straight drag adds
/// nothing, a flick back the other way throws most of it away, a circle adds a full turn.
/// </summary>
float ReadMouse( float dt, out float right, out float up, out float moved )
{
var look = Input.AnalogLook;
right = -look.yaw;
up = -look.pitch;
moved = MathF.Sqrt( right * right + up * up );
if ( moved < 0.1f )
{
_wind -= _wind * MathF.Min( dt * 1.2f, 1f );
return 0f;
}
float x = right / moved, y = up / moved, turn = 0f;
if ( _lastMx != 0f || _lastMy != 0f )
{
turn = MathF.Atan2( _lastMx * y - _lastMy * x, _lastMx * x + _lastMy * y );
if ( MathF.Abs( turn ) > 2.2f ) { _wind *= 0.25f; turn = 0f; }
else _wind += turn;
}
_lastMx = x;
_lastMy = y;
return turn;
}
Angles UpdateAim( float dt )
{
ReadMouse( dt, out float right, out float up, out float moved );
_mouseTravel += moved;
_aimYawOff -= right * AimSensitivity;
_aimElev = Math.Clamp( _aimElev + up * AimSensitivity, AimLowest, AimHighest );
_flick += (moved / dt - _flick) * MathF.Min( dt * 18f, 1f );
// Until it is clear this is not a tap, the rope is only gathered up.
bool maybeTap = Time.Now - _pressAt < TapSeconds && _mouseTravel < TapTravel;
float strength = AimStrength * (1f + FlickBoost * Math.Clamp( _flick / MathF.Max( FlickSpeed, 1f ), 0f, 1f )) / (Slow * Slow);
_rig.DongDrive = Dir( _dongBaseYaw, _aimYawOff, _aimElev );
_rig.DongDriveStrength = maybeTap ? strength * 0.25f : strength;
_power = AimPower;
_knock = 1f;
DongState = TipCracking ? "CRACKING" : "IN HAND";
if ( !_down1 )
{
_holdLook = false;
if ( maybeTap ) StartWhip();
else StartFollow();
return default;
}
if ( Input.Down( "Run" ) || MathF.Abs( _wind ) >= WindToSpin * MathF.PI * 2f )
{
StartSpin( MathF.Abs( _wind ) > 0.5f ? _wind : 1f );
return default;
}
// The body twists toward where the weight is and leans back against it.
float toward = Wrap180( _dongBaseYaw + _aimYawOff - _controller.WorldRotation.Yaw() );
return new Angles( -Math.Clamp( _aimElev, -20f, 90f ) * 0.12f, Math.Clamp( toward / 90f, -1f, 1f ) * BodyTwist, 0f );
}
void StartFollow()
{
_dong = DongMode.Follow;
_dongT = 0f;
_holdLook = false;
}
/// <summary>Let go: nothing pulls it now, and it carries on under its own momentum until it has spent it.</summary>
Angles UpdateFollow()
{
_rig.DongDriveStrength = 0f;
_power = AimPower;
_knock = 1f;
DongState = "FOLLOWING THROUGH";
if ( _dongT >= FollowSeconds * Slow ) _dong = DongMode.Carried;
return default;
}
/// <summary>
/// The tip's speed is watched every frame. Past <see cref="CrackSpeed"/> in the middle of a
/// swing it cracks: a bang, a flash, a small shockwave, and a moment in which everything it
/// touches is hit harder. It has to slow right down before it can crack again.
/// </summary>
void WatchTip()
{
float threshold = CrackSpeed * G;
if ( TipSpeed < threshold * 0.55f ) _cracked = false;
if ( _cracked || TipSpeed < threshold || !Swinging || Time.Now < _nextCrack ) return;
_cracked = true;
_nextCrack = Time.Now + 0.25f;
_crackBonusUntil = Time.Now + 0.16f;
var tip = _rig.DongTip;
float hard = Math.Clamp( TipSpeed / (threshold * 2f), 0.5f, 1f );
Play( "dong_crack", tip, hard, SizePitch( 1f ) );
Rampage.SendShockwave( tip, Reach * CrackRadius * GiantRiders.ShockBonus, CrackShock * hard );
_controller.Kick( -_rig.DongTipVelocity.Normal * (5f * Heft) );
CrackFlash( tip );
Tell( "crack", hard );
}
// HELICOPTER: the spin is a real quantity. It is started, added to with every second of Run
// and every circle of the mouse, kept (it barely slows by itself), and spent in one go.
void StartSpin( float sign )
{
_dong = DongMode.Spin;
_dongT = 0f;
_spinSign = sign >= 0f ? 1f : -1f;
_spinTurned = 0f;
var lie = _rig.DongTip - _rig.DongRoot;
_spinAngle = lie.WithZ( 0f ).Length > 1f ? YawOf( lie ) : _controller.Look.yaw + 180f;
_spinRate = _spinSign * SpinStart / Slow;
_wind = 0f;
Play( "dong_sweep", _rig.DongRoot, 0.9f, SizePitch( 1f ) );
Tell( "spin", 0f );
}
Angles UpdateSpin( float dt )
{
float turn = ReadMouse( dt, out _, out _, out _ );
float pump = 0f;
if ( Input.Down( "Run" ) ) pump += SpinPump * dt;
if ( turn * _spinSign > 0f ) pump += turn * _spinSign / (MathF.PI * 2f) * SpinPerRev;
float most = SpinMax / Slow;
_spinRate += _spinSign * pump / Slow;
_spinRate -= _spinRate * SpinFriction * dt;
_spinRate = Math.Clamp( _spinRate, -most, most );
float s = Spin01;
float step = _spinRate * dt;
float before = _spinTurned;
_spinAngle += step;
_spinTurned += MathF.Abs( step );
_bodySpin += step * SpinBodyShare;
_rig.DongDrive = Dir( 0f, _spinAngle, Lerp( SpinTilt, HeliTilt, s ) );
_rig.DongDriveStrength = SpinStrength * (0.6f + 0.8f * s) / (Slow * Slow);
_power = SpinPower * (0.5f + 1.5f * s);
_knock = 1.2f;
DongState = s >= HoverAt ? "HELICOPTER" : "WINDING UP";
// A whoosh each time round, rising as it winds up.
if ( MathF.Floor( _spinTurned / 360f ) != MathF.Floor( before / 360f ) )
Play( "dong_whoosh", _rig.DongRoot, 0.5f + 0.5f * s, SizePitch( 0.8f + 0.9f * s ) );
// At full speed it takes off: a hop, and then the hover (see OnFixedUpdate).
if ( s >= HoverAt && _controller.Attached && Time.Now >= _nextHop )
{
_nextHop = Time.Now + 1.4f;
_controller.Lunge( Vector3.Up, _controller.JumpSpeed * HoverHop );
Play( "dong_heli", _rig.DongRoot, 1f, 1f );
Tell( "spin", 1f );
}
if ( !_down1 )
{
// A tap while running is still a tap.
if ( Time.Now - _pressAt < TapSeconds ) { _spinRate = 0f; _holdLook = false; StartWhip(); }
else SpinRelease();
return default;
}
return new Angles( 4f, 0f, 8f * _spinSign * (0.5f + s) );
}
void SpinRelease()
{
float s = Spin01;
_holdLook = false;
if ( s < 0.15f ) { _spinRate = 0f; StartFollow(); return; }
_releaseSpin = s;
_dong = DongMode.Release;
_dongT = 0f;
_stage = 0;
_aimYaw = _controller.Look.yaw;
Play( "dong_whoosh", _rig.DongRoot, 1f, SizePitch( 0.7f ) );
}
/// <summary>Everything it had wound up goes into one throw along the line of sight.</summary>
Angles UpdateRelease( float dt )
{
float s = _releaseSpin;
float p = _dongT / MathF.Max( ReleaseSeconds * Slow, 0.01f );
_spinRate -= _spinRate * MathF.Min( dt * 6f, 1f );
_rig.DongDrive = Dir( _aimYaw, 0f, Lerp( 14f, -6f, p ) );
_rig.DongDriveStrength = (p < 0.6f ? ReleaseStrength * (1f + 2f * s) : IdleStrength * 6f) / (Slow * Slow);
_power = SpinPower * (1f + 3f * s);
_knock = 1.5f;
DongState = "RELEASED";
if ( _stage == 0 && p >= 0.38f )
{
_stage = 1;
var forward = Dir( _aimYaw, 0f, 0f );
var from = _rig.DongRoot.WithZ( _controller.WorldPosition.z );
var to = from + forward * (Reach * (1.4f + 2.6f * s));
float tipRadius = _rig.DongRadiusAt( _rig.DongPoints.Count - 1 );
LineBlast( from, to, tipRadius + Reach * 0.18f, ReleaseDamage * s * Rampage.Might, forward * 1400f + Vector3.Up * 900f );
float radius = Reach * (0.6f + 1.2f * s) * GiantRiders.ShockBonus;
float speed = 1400f * (0.6f + s);
Rampage.SendShockwave( to, radius, speed );
StartCracks( from + forward * Reach, forward, radius * 0.6f, speed, (int)MathF.Round( 2f + 6f * s ) );
Thump( 0.4f + 0.6f * s );
Shove( forward, MaxShove * G * (0.4f + 0.6f * s) );
Play( "dong_release", to, 1f, SizePitch( 1f ) );
Tell( "spin_release", s );
}
if ( p >= 1f )
{
_spinRate = 0f;
_dong = DongMode.Carried;
_restUntil = Time.Now + 0.2f;
}
return new Angles( Lerp( -10f, 24f, p ), 0f, 0f );
}
// COMBO: tapped. Wound back to one side, thrown across to the other and left to carry on
// through; then the other way; then up over the back and down along a line in front.
void StartWhip()
{
if ( Time.Now > _comboUntil ) _combo = 0;
_whipIndex = _combo;
bool slam = _whipIndex >= 2;
_dong = DongMode.Whip;
_dongT = 0f;
_stage = 0;
_aimYaw = _controller.Look.yaw;
_buffered = false;
_slamLanded = false;
_impactDone = false;
_holdLook = false;
_power = slam ? SlamPower : WhipPower;
_knock = slam ? 1.3f : 1f;
Combo = _whipIndex + 1;
}
Angles UpdateWhip()
{
const float Wind = 0.26f, Strike = 0.6f;
bool slam = _whipIndex >= 2;
float duration = WhipSeconds * Slow * (slam ? 1.35f : 1f);
float p = _dongT / MathF.Max( duration, 0.01f );
float q = Ease( (p - Wind) / (Strike - Wind) );
if ( slam ) q *= q; // the slam gathers speed on the way down
float strength = p < Wind ? WhipStrength * 0.5f
: p < Strike ? WhipStrength
: Lerp( WhipStrength, IdleStrength * 4f, (p - Strike) / (1f - Strike) );
Vector3 direction;
Angles body;
if ( slam )
{
direction = Dir( _aimYaw, 0f, Lerp( 125f, -24f, q ) );
body = new Angles( Lerp( -24f, 30f, q ), 0f, 0f );
if ( _controller.Attached && p < 0.6f ) _hop = HopHeight * G * MathF.Sin( p / 0.6f * MathF.PI );
DongState = "OVERHEAD SLAM";
}
else
{
float side = _whipIndex == 0 ? -1f : 1f; // the first comes from the right and goes left
direction = Dir( _aimYaw, Lerp( side * 118f, -side * 62f, q ), Lerp( 16f, 2f, q ) );
body = new Angles( 4f, Lerp( side * BodyTwist, -side * BodyTwist, q ), 0f );
DongState = _whipIndex == 0 ? "WHIP LEFT" : "WHIP RIGHT";
}
_rig.DongDrive = direction;
_rig.DongDriveStrength = (_impactDone ? IdleStrength * 6f : strength * (slam ? 1.5f : 1f)) / (Slow * Slow);
if ( _stage == 0 && p >= Wind )
{
_stage = 1;
Play( "dong_whoosh", _rig.DongRoot, 0.8f, SizePitch( slam ? 0.8f : 1.1f ) );
Shove( Dir( _aimYaw, 0f, 0f ), WhipLunge * G );
}
if ( _stage == 1 && p >= Strike )
{
// The weight comes through, and drags the giant a step after it.
_stage = 2;
_controller.Kick( -direction * (3f * Heft) );
if ( !slam ) Shove( direction.WithZ( 0f ), WhipLunge * G * 0.6f * Heft );
}
// The slam has landed when the chain says it hit the ground, or failing that when it must have.
if ( slam && !_impactDone && ((p >= Strike * 0.8f && _slamLanded) || p >= 0.8f) )
{
_impactDone = true;
SlamImpact();
}
if ( p >= 1f )
{
_combo = (_whipIndex + 1) % 3;
_comboUntil = Time.Now + ComboWindow;
if ( _whipIndex == 1 ) _clapUntil = Time.Now + ClapWindow;
_dong = DongMode.Carried;
if ( slam ) _restUntil = Time.Now + FinisherRest;
else if ( _buffered && CanAct ) StartWhip();
}
return body;
}
/// <summary>The overhead slam's landing: everything under the line it came down along is flattened, and a shockwave goes out from the far end.</summary>
void SlamImpact()
{
var forward = Dir( _aimYaw, 0f, 0f );
var tip = _rig.DongTip;
float tipRadius = _rig.DongRadiusAt( _rig.DongPoints.Count - 1 );
float ground = _controller.Attached ? _controller.WorldPosition.z : tip.z - tipRadius * 0.8f;
var from = _rig.DongRoot.WithZ( ground );
var to = tip.WithZ( ground );
if ( (to - from).Length < Reach * 0.5f ) to = from + forward * Reach;
LineBlast( from, to, tipRadius + Reach * SlamWidth, SlamDamage * Rampage.Might, forward * SlamPush + Vector3.Up * SlamPop );
Rampage.SendShockwave( to, Reach * SlamShock * GiantRiders.ShockBonus, SlamShockSpeed );
Thump( 0.55f );
_controller.Kick( Vector3.Down * 12f );
Shove( -forward, WhipLunge * G * 0.5f );
Play( "dong_slam", to, 1f, SizePitch( 1f ) );
Puff( to, 5, Reach * 0.08f );
Scar( (from + to) * 0.5f, YawOf( to - from ), (to - from).Length, tipRadius * 1.6f );
Tell( "slam", 0.6f );
}
/// <summary>Everything within a width of the line between two points on the ground is hit and thrown.</summary>
void LineBlast( Vector3 from, Vector3 to, float width, float damage, Vector3 throwing )
{
var middle = (from + to) * 0.5f;
var near = Rampage.Borrow();
Rampage.TargetsNear( middle, (to - from).Length * 0.5f + width, near );
for ( int i = 0; i < near.Count; i++ )
{
var target = near[i];
var centre = target.Centre.WithZ( from.z );
if ( Closest( from, to, centre, out float along ) > width + target.Radius ) continue;
Hit( target, throwing, damage, Vector3.Lerp( from, to, along ) );
}
Rampage.Return( near );
}
/// <summary>A line of shockwaves that marches away from a place, one after another: the street cracking.</summary>
void StartCracks( Vector3 from, Vector3 forward, float radius, float speed, int count )
{
if ( count <= 0 ) return;
_crackLeft = Math.Min( count, 14 );
_crackNext = Time.Now + CrackInterval;
_crackRadius = radius;
_crackSpeed = speed;
_crackStep = forward * (radius * 0.9f);
_crackAt = from;
Play( "street_crack", from, 1f, 1f );
}
void MarchCrack()
{
while ( _crackLeft > 0 && Time.Now >= _crackNext )
{
_crackLeft--;
_crackNext += CrackInterval;
_crackAt += _crackStep;
Rampage.SendShockwave( _crackAt, _crackRadius, _crackSpeed );
Play( "street_crack", _crackAt, 0.7f, 1f );
Puff( _crackAt, 2, _crackRadius * 0.2f );
Scar( _crackAt, YawOf( _crackStep ), _crackStep.Length * 1.1f, _crackRadius * 0.12f );
}
}
}