Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Completely rewrote the DamageIndicator system since the old system wa…
Browse files Browse the repository at this point in the history
…s flawed. Damage Indicators now work perfectly
  • Loading branch information
finnbainbridge committed Jul 30, 2019
1 parent 544ab36 commit d3675ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
9 changes: 2 additions & 7 deletions Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,10 @@ public void ApplyDamage(float Damage, int AttackerId)
Health = Clamp(Health - Damage, 0, MaxHealth);
// Calculate DamageIndicator angles
Player Attacker = Net.Players[AttackerId];
// Convert our coordinates, and our attacker's coordinates to 2D to make this easier
// Convert the attacker's coordinates to 2D to make this easier
// aka remove height
Vector2 OurPoint = new Vector2(Game.PossessedPlayer.Translation.x, Game.PossessedPlayer.Translation.z);
Vector2 AttackerPoint = new Vector2(Attacker.Translation.x, Attacker.Translation.z);
// Get Angle from us to them
// which is also the angle we've been shot from
float AngleRads = OurPoint.AngleToPoint(AttackerPoint);
// Tell the Angle to the HUD
HUDInstance.ShowDamageIndicator(Rad2Deg(AngleRads)); // Convert to degrees
HUDInstance.ShowDamageIndicator(AttackerPoint); // Convert to degrees
}


Expand Down
18 changes: 10 additions & 8 deletions UI/DamageIndicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
public class DamageIndicator : TextureRect
{
// Angle the bullet came from
float Angle = 90;
// Starting rotation of the character
float OriginalRotation;
Vector2 ShotFirePosition;
float OriginalAngle;
public override void _Ready()
{
// Start transparency Tween in _Ready so we know the Tween has been created
Expand All @@ -17,20 +16,23 @@ public override void _Ready()
}


public void SetTargetAngle(float Angle)
public void SetTargetAngle(Vector2 ShotFirePosition)
{
this.Angle = Angle;
// The rotation we're looking at is the Y rotation
OriginalRotation = Game.PossessedPlayer.RotationDegrees.y;
this.ShotFirePosition = ShotFirePosition;
// Original angle
OriginalAngle = Game.PossessedPlayer.Rotation.y;
}


// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(float delta)
{
// Calculate rotation
// TextureRect rotation is always in degrees, so we must work in degrees :)
RectRotation = Angle- (Game.PossessedPlayer.RotationDegrees.y);
// Calculate our position on a 2D plane
Vector2 OurPoint = new Vector2(Game.PossessedPlayer.Translation.x, Game.PossessedPlayer.Translation.z);
// Get our rotation by getting the angle from where we we're shot from, and adding where we we're looking before
RectRotation = Mathf.Rad2Deg(OurPoint.AngleToPoint(ShotFirePosition)+OriginalAngle);
}


Expand Down
4 changes: 2 additions & 2 deletions UI/HUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ public void RemoveNickLabel(int Id)
}


public void ShowDamageIndicator(float HitAngleDegrees) {
public void ShowDamageIndicator(Vector2 ShotFirePosition) {
// Angle must be in degrees for the DamageIndicator
DamageIndicator Indicator = DamageIndicatorScene.Instance() as DamageIndicator;
Indicator.SetTargetAngle(HitAngleDegrees);
Indicator.SetTargetAngle(ShotFirePosition);
// Add it to its container
DamageIndicatorContainer.AddChild(Indicator);
}
Expand Down
Binary file modified UI/Textures/DamageIndicator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d3675ff

Please sign in to comment.