Skip to content

Commit

Permalink
Implement projectile scale
Browse files Browse the repository at this point in the history
  • Loading branch information
toberge committed Jul 10, 2024
1 parent 4b9e5bb commit 92f358f
Show file tree
Hide file tree
Showing 21 changed files with 3,174 additions and 924 deletions.
28 changes: 17 additions & 11 deletions Assets/LazurController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void RpcFireProjectile(Vector3 output, Vector3 direction)
direction = direction,
maxDistance = MaxDistance,
initializationTime = Time.fixedTime,
size = stats.ProjectileSize
size = stats.ProjectileSize * stats.ProjectileScale
};
projectile.additionalProperties.Clear();

Expand All @@ -100,23 +100,26 @@ private void RpcFireProjectile(Vector3 output, Vector3 direction)

if (rayCasts.Length > 0)
{

Collider collider = rayCasts[0].collider;
var hit = rayCasts[0];
var collider = hit.collider;
lastCollider = collider;
HitboxController hitbox = collider.GetComponent<HitboxController>();

projectile.position = rayCasts[0].point;
OnRicochet?.Invoke(rayCasts[0], ref projectile);
if (hitbox != null)
OnHitboxCollision?.Invoke(hitbox, ref projectile);
OnColliderHit?.Invoke(rayCasts[0], ref projectile);
projectile.position += projectile.direction * hit.distance;

OnRicochet?.Invoke(hit, ref projectile);

if (collider.TryGetComponent<HitboxController>(out var hitbox))
if (!(hitbox.health.Player == player && projectile.distanceTraveled + hit.distance < GunController.InvulnerabilityDistance))
OnHitboxCollision?.Invoke(hitbox, ref projectile);

projectile.distanceTraveled += rayCasts[0].distance;
OnColliderHit?.Invoke(hit, ref projectile);

projectile.direction = Vector3.Reflect(projectile.direction, hit.normal);
projectile.distanceTraveled += hit.distance;
}
else
{
projectile.position = projectile.position + projectile.direction.normalized * (MaxDistance - projectile.distanceTraveled);
projectile.position += projectile.direction.normalized * (MaxDistance - projectile.distanceTraveled);
projectile.active = false;
}

Expand All @@ -136,12 +139,15 @@ private void RpcFireProjectile(Vector3 output, Vector3 direction)

protected override void OnInitialize(GunStats gunstats)
{
Vfx.SetFloat("Size", gunstats.ProjectileScale);
animator.OnInitialize(gunstats);
}

protected override void OnReload(GunStats stats)
{
animator.OnReload(stats);
}

public override void InitializeProjectile(GunStats stats, uint shotID)
{
currentShotID = shotID;
Expand Down
Binary file modified Assets/Models/GunParts/enlarger.fbx
Binary file not shown.
1 change: 1 addition & 0 deletions Assets/Prefabs/Gamestate/StaticInfo.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ MonoBehaviour:
- {fileID: 11400000, guid: 75614ad08cd511f4fa856cd443040455, type: 2}
- {fileID: 11400000, guid: 6955edf1e31801642a2f47defb820d36, type: 2}
- {fileID: 11400000, guid: 87e98f42380f122a486cd5034ef1d278, type: 2}
- {fileID: 11400000, guid: 1e8a76909fc7b284dae3c37ebcf4d7ce, type: 2}
bodyAuction: {fileID: 11400000, guid: d9d421bb70476fb4889310ad4f1d310f, type: 2}
barrelAuction: {fileID: 11400000, guid: 6d47b14bed8c37e45af1c831948f3385, type: 2}
extensionAuction: {fileID: 11400000, guid: ad4a13bed7ceda243beb3334b23d48b0, type: 2}
Expand Down
6 changes: 5 additions & 1 deletion Assets/Prefabs/GunParts/CannonBarrel.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ MonoBehaviour:
addition: 0
multiplier: 0
exponential: 0.75
- name: ScreenShakeFactor
addition: 0.3
multiplier: 0
exponential: 1
outputs:
- {fileID: 1160446427348008624}
midpoint: {fileID: 6064389157985578044}
Expand Down Expand Up @@ -541,7 +545,7 @@ VFXRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8858774212536550383}
m_Enabled: 1
m_CastShadows: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
Expand Down
58 changes: 38 additions & 20 deletions Assets/Prefabs/GunParts/EnlargerExtension.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2011919946570164602}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.284}
m_LocalPosition: {x: 0, y: 0, z: 0.328}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -55,7 +55,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4320344545349446905}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.235}
m_LocalPosition: {x: 0, y: 0, z: 0.486}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
Expand All @@ -72,7 +72,6 @@ GameObject:
m_Component:
- component: {fileID: 8196151136836888530}
- component: {fileID: 7575752308601990708}
- component: {fileID: -1314935375335004500}
m_Layer: 0
m_Name: EnlargerExtension
m_TagString: Untagged
Expand Down Expand Up @@ -115,26 +114,29 @@ MonoBehaviour:
syncInterval: 0
statModifiers:
- name: ScreenShakeFactor
addition: 0.5
addition: 0.7
multiplier: 0
exponential: 1
- name: ProjectileScale
addition: 0
multiplier: 0
exponential: 3
- name: ProjectileDamage
addition: 0
multiplier: 0.5
exponential: 1
- name: ProjectileSpeedFactor
addition: 0
multiplier: 0
exponential: 0.5
- name: Firerate
addition: 0
multiplier: 0
exponential: 0.5
outputs:
- {fileID: 932626616956480431}
midpoint: {fileID: 5729402012261899082}
model: {fileID: 993201347869452232}
--- !u!114 &-1314935375335004500
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8350213044137146345}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 586f8df323151294a9220b1f0d464466, type: 3}
m_Name:
m_EditorClassIdentifier:
multiplier: 10
--- !u!1001 &74844362063714969
PrefabInstance:
m_ObjectHideFlags: 0
Expand All @@ -147,17 +149,29 @@ PrefabInstance:
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5523b592edc638e439fe26cdeebe8b79, type: 3}
propertyPath: m_LocalScale.x
value: 1.2
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5523b592edc638e439fe26cdeebe8b79, type: 3}
propertyPath: m_LocalScale.y
value: 1.2
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5523b592edc638e439fe26cdeebe8b79, type: 3}
propertyPath: m_LocalScale.z
value: 1.2
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5523b592edc638e439fe26cdeebe8b79, type: 3}
propertyPath: m_LocalPosition.x
value: 0
value: -0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5523b592edc638e439fe26cdeebe8b79, type: 3}
propertyPath: m_LocalPosition.y
value: -0.053
value: -0.066
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5523b592edc638e439fe26cdeebe8b79, type: 3}
propertyPath: m_LocalPosition.z
value: 0.245
value: 0.2918
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5523b592edc638e439fe26cdeebe8b79, type: 3}
propertyPath: m_LocalRotation.w
Expand Down Expand Up @@ -187,6 +201,10 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5523b592edc638e439fe26cdeebe8b79, type: 3}
propertyPath: m_ConstrainProportionsScale
value: 1
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 5523b592edc638e439fe26cdeebe8b79, type: 3}
propertyPath: m_Name
value: enlarger
Expand Down
13 changes: 0 additions & 13 deletions Assets/Prefabs/GunParts/LazurBarrel.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ GameObject:
m_Component:
- component: {fileID: 6030259934304341444}
- component: {fileID: 5695477544615188222}
- component: {fileID: 2680724073785080762}
- component: {fileID: 8865490531545464824}
- component: {fileID: 4273715955371138616}
- component: {fileID: 4536155953706137537}
Expand Down Expand Up @@ -583,18 +582,6 @@ MonoBehaviour:
attachmentPoints:
- {fileID: 2021858193588301184}
muzzleFlash: {fileID: 1933672864586849248}
--- !u!114 &2680724073785080762
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1569365569997936042}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c2bb47b3ca3e5854f9029b0888d83a3e, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &8865490531545464824
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
10 changes: 1 addition & 9 deletions Assets/Scenes/Menu.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 785370674}
m_IndirectSpecularColor: {r: 0.062317036, g: 0.21927114, b: 0.4949812, a: 1}
m_IndirectSpecularColor: {r: 0.99999905, g: 0, b: 0.99999905, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -312,14 +312,6 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 3717336014748129540, guid: 0e2ad36662a02c3488301a5286b27635, type: 3}
propertyPath: extensions.Array.size
value: 9
objectReference: {fileID: 0}
- target: {fileID: 3717336014748129540, guid: 0e2ad36662a02c3488301a5286b27635, type: 3}
propertyPath: extensions.Array.data[8]
value:
objectReference: {fileID: 11400000, guid: 1e8a76909fc7b284dae3c37ebcf4d7ce, type: 2}
- target: {fileID: 8579357797008554893, guid: 0e2ad36662a02c3488301a5286b27635, type: 3}
propertyPath: m_Name
value: StaticInfo
Expand Down
4 changes: 2 additions & 2 deletions Assets/ScriptableObjects/Items/EnlargerExtension.asset
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
id: Enlarger
displayName: Enlarger
secretName:
displayDescription: What if you're bullets were *bigger*
secretName: Enormous
displayDescription: Bigger, slower projectiles
extendedDescription:
loreDescription:
augmentType: 2
Expand Down
2 changes: 1 addition & 1 deletion Assets/ScriptableObjects/Items/HatBarrel.asset
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MonoBehaviour:
id: Hatapult
displayName: Hat-apult
secretName: tipper
displayDescription: Shoot hats that get stuck to your enemies!
displayDescription: Shoot hats that stick to your enemies!
extendedDescription:
loreDescription:
augmentType: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using UnityEngine.Serialization;
using Mirror;
using System.Runtime.InteropServices;

/// <summary>
/// Class that processes and renders mesh projectiles
Expand Down Expand Up @@ -66,8 +67,6 @@ protected override void Awake()
positionActiveBuffer.Initialize(maxProjectiles);
vfx.SetGraphicsBuffer("Positions", positionActiveBuffer.Buffer);
vfx.SetInt("MaxParticleCount", maxProjectiles);
vfx.SetFloat("Size", visualSize);
vfx.SendEvent(VisualEffectAsset.PlayEventID);

if (!gunController || !gunController.Player)
return;
Expand All @@ -76,6 +75,8 @@ protected override void Awake()

protected override void OnInitialize(GunStats gunstats)
{
vfx.SetFloat("Size", visualSize * gunstats.ProjectileScale);
vfx.SendEvent(VisualEffectAsset.PlayEventID);
animator.OnInitialize(gunstats);
}

Expand Down Expand Up @@ -126,7 +127,14 @@ private void RpcFireProjectile(Vector3 output, Vector3 direction, Quaternion rot
loadedProjectile.position = output;
loadedProjectile.direction = direction;
loadedProjectile.rotation = rotation;
loadedProjectile.size = size;

// Hat hitbox should be smaller when large :/
// Otherwise they bounce off weirdly
if (player.identity.Barrel.id == "Hatapult")
loadedProjectile.size = size * (1 + (stats.ProjectileScale - 1) * .3f);
else
loadedProjectile.size = size * stats.ProjectileScale;

loadedProjectile.additionalProperties["lastCollider"] = null;

projectiles[currentStateIndex] = loadedProjectile;
Expand Down Expand Up @@ -177,16 +185,16 @@ private void UpdateProjectile(ProjectileState state)
state.active = false;
}

var collisions = ProjectileMotions.GetPathCollisions(state, collisionLayers).Where(p => p.collider != lastCollider).ToArray();
var collisions = ProjectileMotions.GetPathCollisions(state, collisionLayers).Where(p => p.collider != lastCollider).OrderBy(p => p.distance).ToArray();

state.additionalProperties["lastCollider"] = collisions.Length > 0 ? collisions[0].collider : null;

if (collisions.Length <= 0) return;


if (collisions[0].collider.TryGetComponent<HitboxController>(out HitboxController hitbox))
if (collisions[0].collider.TryGetComponent<HitboxController>(out var hitbox))
{
var hasHitYourselfTooEarly = hitbox.health.Player == player && state.distanceTraveled < player.GunController.OutputTransitionDistance;
var hasHitYourselfTooEarly = hitbox.health.Player == player && state.distanceTraveled < GunController.InvulnerabilityDistance;
if (hasHitYourselfTooEarly)
return;

Expand Down
13 changes: 9 additions & 4 deletions Assets/Scripts/Augment/BulletController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private void Start()
trail.SetInt("StripLength", vfxPositionsPerSample * collisionSamples);
trail.SetInt("TextureSize", vfxPositionsPerSample * collisionSamples * bulletsPerShot);
trail.SetInt("TrailsPerEvent", bulletsPerShot);
trail.SetFloat("Size", stats.ProjectileScale);

if (isServer)
RpcSeedRandom(random.Next());
Expand All @@ -74,10 +75,12 @@ public void SetTrail(VisualEffect newTrail)
{
trailPositionBuffer.Buffer?.Release();
trail = newTrail;
trail.SetFloat("Size", stats.ProjectileScale);
}

protected override void OnInitialize(GunStats gunstats)
{
trail.SetFloat("Size", stats.ProjectileScale);
animator.OnInitialize(gunstats);
}

Expand Down Expand Up @@ -126,8 +129,10 @@ private void RpcFireProjectile(Vector3 output, Vector3 direction, Quaternion rot
rotation = randomSpread * rotation,
initializationTime = Time.fixedTime,
speedFactor = stats.ProjectileSpeedFactor,
gravity = stats.ProjectileGravityModifier * 9.81f
gravity = stats.ProjectileGravityModifier * 9.81f,
size = Mathf.Max(0, (stats.ProjectileScale - 1)*.1f),
};

projectile.additionalProperties.Clear();
projectile.hitHealthControllers.Clear();

Expand Down Expand Up @@ -159,16 +164,16 @@ private void RpcFireProjectile(Vector3 output, Vector3 direction, Quaternion rot
var collider = collisions[i].collider;
HitboxController hitbox = collider.GetComponent<HitboxController>();
if (hitbox != null)
if (hitbox.health.Player == player && projectile.distanceTraveled < player.GunController.OutputTransitionDistance)
if (hitbox.health.Player == player && projectile.distanceTraveled < GunController.InvulnerabilityDistance)
continue;

projectile.position = collisions[i].point;
projectile.position += projectile.direction * collisions[i].distance;
if (hitbox != null)
OnHitboxCollision?.Invoke(hitbox, ref projectile);

OnColliderHit?.Invoke(collisions[i], ref projectile);

if (totalCollisions == this.collisionsBeforeInactive)
if (totalCollisions == collisionsBeforeInactive)
projectile.active = false;

if (sampleNum < collisionSamples)
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/Augment/BulletModifiers/ExplosionModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public void Detach(ProjectileController projectile)
private void Explode(RaycastHit other, ref ProjectileState state)
{
var instance = Instantiate(explosion, state.position, Quaternion.identity);
instance.Radius *= projectile.stats.ProjectileScale;
instance.Init();

var targets = instance.Explode(player);

// Trigger on hit, excluding this effect and using the scaled damage from the explosion
Expand Down
Loading

0 comments on commit 92f358f

Please sign in to comment.