Skip to content

Commit

Permalink
Basic fall damage implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
timmybo5 committed Jan 1, 2023
1 parent 9475a9c commit 3a73c6c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
18 changes: 17 additions & 1 deletion code/swb_base/obsolete/PlayerBase.Base.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using Sandbox;

/* Result from Pain Day 4, this will be here temporarily until it is clear how templates work */
Expand Down Expand Up @@ -360,6 +361,21 @@ public virtual void TakeDamageBase(DamageInfo info)
}
}

public virtual void DoFallDamage(TimeSince timeSinceFalling, Vector3 velocity)
{
if (velocity.z > -600) return;

timeSinceFalling /= 2;
velocity /= 12;
var damageInfo = new DamageInfo()
{
Damage = Math.Abs(velocity.z) * (1 + timeSinceFalling),
Force = velocity
};

TakeDamage(damageInfo);
}

public override void OnChildAdded(Entity child)
{
Inventory?.OnChildAdded(child);
Expand Down
32 changes: 28 additions & 4 deletions code/swb_base/obsolete/controllers/PlayerWalkController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using Sandbox;
using Sandbox;

/* Result from Pain Day 4, this will be here temporarily until it is clear how templates work */

Expand Down Expand Up @@ -34,7 +33,6 @@ public partial class PlayerWalkController : PlayerBaseController
public PlayerDuck Duck;
public PlayerUnstuck Unstuck;


public PlayerWalkController()
{
Duck = new PlayerDuck(this);
Expand Down Expand Up @@ -236,7 +234,7 @@ public override void Simulate()
Velocity = Velocity.WithZ(0);
}

// CheckFalling(); // fall damage etc
CheckFalling();

// Land Sound
// Swim Sounds
Expand All @@ -261,6 +259,32 @@ public override void Simulate()

}

public bool IsFalling { get; private set; }
public Vector3 FallingVelocity { get; private set; }
public TimeSince TimeSinceFalling { get; private set; }

public virtual void CheckFalling()
{
if (GroundEntity == null)
{
if (!IsFalling)
TimeSinceFalling = 0;

IsFalling = true;
FallingVelocity = Velocity;
}
else if (GroundEntity != null && IsFalling)
{
IsFalling = false;

if (Game.IsServer)
{
var ply = Pawn as PlayerBase;
ply.DoFallDamage(TimeSinceFalling, FallingVelocity);
}
}
}

public virtual float GetWishSpeed()
{
var ws = Duck.GetWishSpeed();
Expand Down

0 comments on commit 3a73c6c

Please sign in to comment.