Makes projectile speed configurable in gun system (#10535)
This commit is contained in:
@@ -58,14 +58,14 @@ public sealed partial class GunSystem : SharedGunSystem
|
|||||||
for (var i = 0; i < cartridge.Count; i++)
|
for (var i = 0; i < cartridge.Count; i++)
|
||||||
{
|
{
|
||||||
var uid = Spawn(cartridge.Prototype, fromCoordinates);
|
var uid = Spawn(cartridge.Prototype, fromCoordinates);
|
||||||
ShootProjectile(uid, angles[i].ToVec(), user);
|
ShootProjectile(uid, angles[i].ToVec(), user, gun.ProjectileSpeed);
|
||||||
shotProjectiles.Add(uid);
|
shotProjectiles.Add(uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var uid = Spawn(cartridge.Prototype, fromCoordinates);
|
var uid = Spawn(cartridge.Prototype, fromCoordinates);
|
||||||
ShootProjectile(uid, mapDirection, user);
|
ShootProjectile(uid, mapDirection, user, gun.ProjectileSpeed);
|
||||||
shotProjectiles.Add(uid);
|
shotProjectiles.Add(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,11 +98,11 @@ public sealed partial class GunSystem : SharedGunSystem
|
|||||||
{
|
{
|
||||||
RemComp<AmmoComponent>(newAmmo.Owner);
|
RemComp<AmmoComponent>(newAmmo.Owner);
|
||||||
// TODO: Someone can probably yeet this a billion miles so need to pre-validate input somewhere up the call stack.
|
// TODO: Someone can probably yeet this a billion miles so need to pre-validate input somewhere up the call stack.
|
||||||
ThrowingSystem.TryThrow(newAmmo.Owner, mapDirection, 20f, user);
|
ThrowingSystem.TryThrow(newAmmo.Owner, mapDirection, gun.ProjectileSpeed, user);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShootProjectile(newAmmo.Owner, mapDirection, user);
|
ShootProjectile(newAmmo.Owner, mapDirection, user, gun.ProjectileSpeed);
|
||||||
break;
|
break;
|
||||||
case HitscanPrototype hitscan:
|
case HitscanPrototype hitscan:
|
||||||
var ray = new CollisionRay(fromMap.Position, mapDirection.Normalized, hitscan.CollisionMask);
|
var ray = new CollisionRay(fromMap.Position, mapDirection.Normalized, hitscan.CollisionMask);
|
||||||
@@ -155,11 +155,11 @@ public sealed partial class GunSystem : SharedGunSystem
|
|||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShootProjectile(EntityUid uid, Vector2 direction, EntityUid? user = null)
|
public void ShootProjectile(EntityUid uid, Vector2 direction, EntityUid? user = null, float speed = 20f)
|
||||||
{
|
{
|
||||||
var physics = EnsureComp<PhysicsComponent>(uid);
|
var physics = EnsureComp<PhysicsComponent>(uid);
|
||||||
physics.BodyStatus = BodyStatus.InAir;
|
physics.BodyStatus = BodyStatus.InAir;
|
||||||
physics.LinearVelocity = direction.Normalized * 20f;
|
physics.LinearVelocity = direction.Normalized * speed;
|
||||||
|
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,6 +85,12 @@ public class GunComponent : Component
|
|||||||
[ViewVariables(VVAccess.ReadWrite), DataField("fireRate")]
|
[ViewVariables(VVAccess.ReadWrite), DataField("fireRate")]
|
||||||
public float FireRate = 8f;
|
public float FireRate = 8f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// How fast the projectile moves.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables(VVAccess.ReadWrite), DataField("projectileSpeed")]
|
||||||
|
public float ProjectileSpeed = 20f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When the gun is next available to be shot.
|
/// When the gun is next available to be shot.
|
||||||
/// Can be set multiple times in a single tick due to guns firing faster than a single tick time.
|
/// Can be set multiple times in a single tick due to guns firing faster than a single tick time.
|
||||||
|
|||||||
Reference in New Issue
Block a user