Skip to content

Commit

Permalink
Projectile Particles
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed Jan 6, 2024
1 parent edb2835 commit 58595f6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ public void CheckHits(float delta)

foreach (var hitInfo in intersects)
{
if (QueuedDispose)
break;
double dist = len * hitInfo.Fraction;
ProjectileHit(hitInfo.HitEntity);
ProjectileHit(hitInfo.HitEntity, hitInfo.Position);
}
}

public void ProjectileHit(IMyEntity impact)
public void ProjectileHit(IMyEntity impact, Vector3D impactPosition)
{
if (impact.EntityId == Firer)
return;
Expand All @@ -122,6 +124,8 @@ public void ProjectileHit(IMyEntity impact)
else if (impact is IMyCharacter)
DamageHandler.QueueEvent(new DamageEvent(impact, DamageEvent.DamageEntType.Character, this));

DrawImpactParticle(impactPosition);

RemainingImpacts -= 1;
if (RemainingImpacts <= 0)
QueueDispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class ProjectileDefinitionManager
SlimBlockDamageMod = 25,
FatBlockDamageMod = 1,
BaseDamage = 100,
AreaDamage = 50,
AreaDamage = 100,
AreaRadius = 15,
MaxImpacts = 1,
},
Expand All @@ -37,8 +37,8 @@ internal class ProjectileDefinitionManager
Model = "",
TrailTexture = "",
TrailFadeTime = 0,
AttachedParticle = "",
ImpactParticle = "",
AttachedParticle = "Smoke_Missile",
ImpactParticle = "Explosion_LargeCaliberShell_Backup",
VisibleChance = 1,
},
Audio = new Audio()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Heart_Module.Data.Scripts.HeartModule.Debug;
using Sandbox.ModAPI;
using VRage.Game;
using VRage.Game.Entity;
using VRageMath;
using VRageRender;
Expand All @@ -10,23 +11,58 @@ partial class Projectile
{
MyBillboard ProjectileBillboard;
MyEntity ProjectileEntity;
MyParticleEffect ProjectileEffect;
uint RenderId = 0;

internal void InitDrawing()
{
ProjectileBillboard = new MyBillboard();
ProjectileEntity = new MyEntity();
RenderId = ProjectileEntity.Render.GetRenderObjectID();
}

public void DrawUpdate(float delta)
{
Vector3D visualPosition = Position + (InheritedVelocity + Direction * (Velocity + Definition.PhysicalProjectile.Acceleration * delta)) * delta;
// Temporary debug draw
DebugDraw.AddPoint(Position + (InheritedVelocity + Direction * (Velocity + Definition.PhysicalProjectile.Acceleration * delta)) * delta, Color.Green, 0.000001f);

//DebugDraw.AddPoint(visualPosition, Color.Green, 0.000001f);

if (Definition.Visual.AttachedParticle != "")
{
MatrixD matrix = MatrixD.CreateWorld(visualPosition, Direction, Vector3D.Cross(Direction, Vector3D.Up));

if (ProjectileEffect == null)
{
MyParticlesManager.TryCreateParticleEffect(Definition.Visual.AttachedParticle, ref matrix, ref visualPosition, RenderId, out ProjectileEffect);
}
else
{
ProjectileEffect.WorldMatrix = matrix;
}
}
}

internal void CloseDrawing()
private void DrawImpactParticle(Vector3D ImpactPosition)
{
if (Definition.Visual.ImpactParticle == "")
return;

MatrixD matrix = MatrixD.CreateTranslation(ImpactPosition);
MyParticleEffect hitEffect;
if (MyParticlesManager.TryCreateParticleEffect(Definition.Visual.ImpactParticle, ref matrix, ref ImpactPosition, uint.MaxValue, out hitEffect))
{
MyAPIGateway.Utilities.ShowNotification("Spawned particle at " + hitEffect.WorldMatrix.Translation);
//hitEffect.UserScale = av.AmmoDef.AmmoGraphics.Particles.Hit.Extras.Scale;
//hitEffect.Velocity = av.Hit.HitVelocity;

if (hitEffect.Loop)
hitEffect.Stop();
}
}

internal void CloseDrawing()
{
ProjectileEffect?.Close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ public override void UpdateAfterSimulation()
j = 0;
try
{
Random r = new Random();
Vector3D randVec = new Vector3D(r.NextDouble(), r.NextDouble(), r.NextDouble()).Normalized();
Projectile p = new Projectile(new SerializableProjectile()
{
IsActive = true,
Id = 0,
DefinitionId = 0,
Position = MyAPIGateway.Session.Player?.GetPosition() ?? Vector3D.Zero, // CHECK OUT HOW HARD I CAN PISS
Direction = MyAPIGateway.Session.Player?.Controller.ControlledEntity.Entity.WorldMatrix.Forward ?? Vector3D.Forward,
Direction = MyAPIGateway.Session.Player?.Controller.ControlledEntity.Entity.WorldMatrix.Forward.Rotate(randVec, r.NextDouble() * 0.0873 - 0.04365) ?? Vector3D.Forward,
Velocity = 100,
Timestamp = DateTime.Now.Ticks,
InheritedVelocity = Vector3D.Zero,
Expand Down

0 comments on commit 58595f6

Please sign in to comment.