feat: Ships set color of mesh over property -> less prefab variants, improved hit feedback, improved meshes and Triggers

This commit is contained in:
Jakob Feldmann 2024-05-14 15:00:55 +02:00
parent 83ce65aec0
commit cca4b75827
25 changed files with 1314 additions and 49 deletions

View File

@ -452,7 +452,7 @@ MonoBehaviour:
<SpawnableCollectionId>k__BackingField: 0 <SpawnableCollectionId>k__BackingField: 0
_scenePathHash: 0 _scenePathHash: 0
<SceneId>k__BackingField: 0 <SceneId>k__BackingField: 0
<AssetPathHash>k__BackingField: 8202943414176531587 <AssetPathHash>k__BackingField: 13364203004141276529
--- !u!114 &7840113418566161560 --- !u!114 &7840113418566161560
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -192,6 +192,7 @@ MonoBehaviour:
gravityEffect: {fileID: 8590080437221755141} gravityEffect: {fileID: 8590080437221755141}
jetFlameEffect: {fileID: 3312185522185408775} jetFlameEffect: {fileID: 3312185522185408775}
smokeTrailEffect: {fileID: 978131449706323191} smokeTrailEffect: {fileID: 978131449706323191}
fireController: {fileID: 0}
--- !u!114 &394654179909484550 --- !u!114 &394654179909484550
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -234,7 +235,7 @@ MonoBehaviour:
<SpawnableCollectionId>k__BackingField: 0 <SpawnableCollectionId>k__BackingField: 0
_scenePathHash: 0 _scenePathHash: 0
<SceneId>k__BackingField: 0 <SceneId>k__BackingField: 0
<AssetPathHash>k__BackingField: 16670295706234430249 <AssetPathHash>k__BackingField: 5551583836262103703
--- !u!114 &8307104301583811584 --- !u!114 &8307104301583811584
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -192,6 +192,7 @@ MonoBehaviour:
gravityEffect: {fileID: 2930093712651127642} gravityEffect: {fileID: 2930093712651127642}
jetFlameEffect: {fileID: 3312185522185408775} jetFlameEffect: {fileID: 3312185522185408775}
smokeTrailEffect: {fileID: 978131449706323191} smokeTrailEffect: {fileID: 978131449706323191}
fireController: {fileID: 0}
--- !u!114 &394654179909484550 --- !u!114 &394654179909484550
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -234,7 +235,7 @@ MonoBehaviour:
<SpawnableCollectionId>k__BackingField: 0 <SpawnableCollectionId>k__BackingField: 0
_scenePathHash: 0 _scenePathHash: 0
<SceneId>k__BackingField: 0 <SceneId>k__BackingField: 0
<AssetPathHash>k__BackingField: 13918576962987486207 <AssetPathHash>k__BackingField: 10015891062238479949
--- !u!114 &8307104301583811584 --- !u!114 &8307104301583811584
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -192,6 +192,7 @@ MonoBehaviour:
gravityEffect: {fileID: 5356225948148490788} gravityEffect: {fileID: 5356225948148490788}
jetFlameEffect: {fileID: 3312185522185408775} jetFlameEffect: {fileID: 3312185522185408775}
smokeTrailEffect: {fileID: 978131449706323191} smokeTrailEffect: {fileID: 978131449706323191}
fireController: {fileID: 0}
--- !u!114 &394654179909484550 --- !u!114 &394654179909484550
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -234,7 +235,7 @@ MonoBehaviour:
<SpawnableCollectionId>k__BackingField: 0 <SpawnableCollectionId>k__BackingField: 0
_scenePathHash: 0 _scenePathHash: 0
<SceneId>k__BackingField: 0 <SceneId>k__BackingField: 0
<AssetPathHash>k__BackingField: 3827021182781196237 <AssetPathHash>k__BackingField: 5851826624730448275
--- !u!114 &8307104301583811584 --- !u!114 &8307104301583811584
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 75db4d0681fa51f4bb6106997f11022e
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -25,9 +25,11 @@ MonoBehaviour:
minBoostCapacity: 0.5 minBoostCapacity: 0.5
boostMagnitude: 2 boostMagnitude: 2
outsideBoostRate: 0 outsideBoostRate: 0
boostAntiGravityFactor: 0.5 boostAntiGravityFactor: 0.62
stunLooseControlFactor: 0.1 stunLooseControlFactor: 0.1
tackleCriticalStunTime: 0.6 tacklingGraceTime: 0.6
tackleBodyStunTime: 0.3 tackledGraceTime: 0.3
criticalTacklePowerFactor: 60 tackledCriticalStunTime: 0.6
tackledBodyStunTime: 0.3
criticalTacklePowerFactor: 300
normalTacklePowerFactor: 100 normalTacklePowerFactor: 100

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 08c48ab20db07b44782d8639776cba72
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,37 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f5cabb9de76fbfa49b5ccac30cd25c68, type: 3}
m_Name: BaseShip 2
m_EditorClassIdentifier:
baseProps: {fileID: 11400000, guid: 8bb9b96c7ef17e94bbd897292f08cd4e, type: 2}
shipPrefab: {fileID: 1372816401649438144, guid: 75db4d0681fa51f4bb6106997f11022e, type: 3}
shipName: Test Ship 2
shipHullColor: {r: 0.6528301, g: 0.6528301, b: 0.6528301, a: 1}
thrustAccelerationModifier: 1
steerVelocityModifier: 1
normalMaxVelocityModifier: 1
absolutMaxVelocityModifier: 1
antiDriftAmountModifier: 1
minAntiDriftFactorModifier: 1
normalDragModifier: 1
maximumDragModifier: 1
torqueDragModifier: 1
maxBoostCapacityModifier: 1
minBoostCapacityModifier: 1
boostMagnitudeModifier: 1
outsideBoostRateModifier: 1
boostAntiGravityFactorModifier: 1
stunLooseControlFactorModifier: 1
tackleCriticalStunTimeModifier: 1
tackleBodyStunTimeModifier: 1
criticalTacklePowerFactorModifier: 1
normalTacklePowerFactorModifier: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 233a6e3591923bc418e8e78ae1661cec
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,37 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f5cabb9de76fbfa49b5ccac30cd25c68, type: 3}
m_Name: BaseShip
m_EditorClassIdentifier:
baseProps: {fileID: 11400000, guid: 8bb9b96c7ef17e94bbd897292f08cd4e, type: 2}
shipPrefab: {fileID: 1372816401649438144, guid: 75db4d0681fa51f4bb6106997f11022e, type: 3}
shipName: Test Ship
shipHullColor: {r: 0.8792453, g: 0.8792453, b: 0.8792453, a: 1}
thrustAccelerationModifier: 1
steerVelocityModifier: 1
normalMaxVelocityModifier: 1
absolutMaxVelocityModifier: 1
antiDriftAmountModifier: 1
minAntiDriftFactorModifier: 1
normalDragModifier: 1
maximumDragModifier: 1
torqueDragModifier: 1
maxBoostCapacityModifier: 1
minBoostCapacityModifier: 1
boostMagnitudeModifier: 1
outsideBoostRateModifier: 1
boostAntiGravityFactorModifier: 1
stunLooseControlFactorModifier: 1
tackleCriticalStunTimeModifier: 1
tackleBodyStunTimeModifier: 1
criticalTacklePowerFactorModifier: 1
normalTacklePowerFactorModifier: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 574c42ee41c481a49a8ec93588407090
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -13,8 +13,9 @@ MonoBehaviour:
m_Name: BlueShip m_Name: BlueShip
m_EditorClassIdentifier: m_EditorClassIdentifier:
baseProps: {fileID: 11400000, guid: 8bb9b96c7ef17e94bbd897292f08cd4e, type: 2} baseProps: {fileID: 11400000, guid: 8bb9b96c7ef17e94bbd897292f08cd4e, type: 2}
shipPrefab: {fileID: 1372816401649438144, guid: 65cd4fa5e050652409dd9b062365c7e8, type: 3} shipPrefab: {fileID: 1372816401649438144, guid: 75db4d0681fa51f4bb6106997f11022e, type: 3}
shipName: Blue Blitz shipName: Blue Blitz
shipHullColor: {r: 0, g: 0.62125206, b: 1, a: 1}
thrustAccelerationModifier: 1 thrustAccelerationModifier: 1
steerVelocityModifier: 1 steerVelocityModifier: 1
normalMaxVelocityModifier: 1 normalMaxVelocityModifier: 1

View File

@ -13,8 +13,9 @@ MonoBehaviour:
m_Name: GreenShip m_Name: GreenShip
m_EditorClassIdentifier: m_EditorClassIdentifier:
baseProps: {fileID: 11400000, guid: 8bb9b96c7ef17e94bbd897292f08cd4e, type: 2} baseProps: {fileID: 11400000, guid: 8bb9b96c7ef17e94bbd897292f08cd4e, type: 2}
shipPrefab: {fileID: 1372816401649438144, guid: 9f3e27e33167d704e941e42ded557111, type: 3} shipPrefab: {fileID: 1372816401649438144, guid: 75db4d0681fa51f4bb6106997f11022e, type: 3}
shipName: Green Danger shipName: Green Danger
shipHullColor: {r: 0, g: 1, b: 0.40690804, a: 1}
thrustAccelerationModifier: 1 thrustAccelerationModifier: 1
steerVelocityModifier: 1 steerVelocityModifier: 1
normalMaxVelocityModifier: 1 normalMaxVelocityModifier: 1

View File

@ -13,8 +13,9 @@ MonoBehaviour:
m_Name: PurpleShip m_Name: PurpleShip
m_EditorClassIdentifier: m_EditorClassIdentifier:
baseProps: {fileID: 11400000, guid: 8bb9b96c7ef17e94bbd897292f08cd4e, type: 2} baseProps: {fileID: 11400000, guid: 8bb9b96c7ef17e94bbd897292f08cd4e, type: 2}
shipPrefab: {fileID: 1372816401649438144, guid: 5934082513feac04a9b875fc86abe70b, type: 3} shipPrefab: {fileID: 1372816401649438144, guid: 75db4d0681fa51f4bb6106997f11022e, type: 3}
shipName: Purple Haze shipName: Purple Haze
shipHullColor: {r: 0.6345311, g: 0.17924517, b: 1, a: 1}
thrustAccelerationModifier: 1 thrustAccelerationModifier: 1
steerVelocityModifier: 1 steerVelocityModifier: 1
normalMaxVelocityModifier: 1 normalMaxVelocityModifier: 1

View File

@ -13,8 +13,9 @@ MonoBehaviour:
m_Name: RedShip m_Name: RedShip
m_EditorClassIdentifier: m_EditorClassIdentifier:
baseProps: {fileID: 11400000, guid: 8bb9b96c7ef17e94bbd897292f08cd4e, type: 2} baseProps: {fileID: 11400000, guid: 8bb9b96c7ef17e94bbd897292f08cd4e, type: 2}
shipPrefab: {fileID: 1372816401649438144, guid: 46f84e56340e83e4ba7c6abbccd2ae3f, type: 3} shipPrefab: {fileID: 1372816401649438144, guid: 75db4d0681fa51f4bb6106997f11022e, type: 3}
shipName: Red Menace shipName: Red Menace
shipHullColor: {r: 0.9924528, g: 0.18470371, b: 0.1404413, a: 1}
thrustAccelerationModifier: 1 thrustAccelerationModifier: 1
steerVelocityModifier: 1 steerVelocityModifier: 1
normalMaxVelocityModifier: 1 normalMaxVelocityModifier: 1

View File

@ -38,10 +38,14 @@ public class BaseShipProperties : ScriptableObject
public float boostAntiGravityFactor = 0.33f; public float boostAntiGravityFactor = 0.33f;
[Tooltip("The factor by which the player looses control over the character when being stunned (0 = no control).")] [Tooltip("The factor by which the player looses control over the character when being stunned (0 = no control).")]
public float stunLooseControlFactor = 0.1f; public float stunLooseControlFactor = 0.1f;
[Tooltip("Time until the tackling player can be tackled again")]
public float tacklingGraceTime = 0.6f;
[Tooltip("Time until the tackled player can be tackled again")]
public float tackledGraceTime = 0.6f;
[Tooltip("The time it takes for a critically stunned character to be controlable again.")] [Tooltip("The time it takes for a critically stunned character to be controlable again.")]
public float tackleCriticalStunTime = 0.6f; public float tackledCriticalStunTime = 0.6f;
[Tooltip("The time it takes for a normally stunned character to be controlable again.")] [Tooltip("The time it takes for a normally stunned character to be controlable again.")]
public float tackleBodyStunTime = 0.3f; public float tackledBodyStunTime = 0.3f;
[Tooltip("The power with which the character is tackled away, when hit critically.")] [Tooltip("The power with which the character is tackled away, when hit critically.")]
public float criticalTacklePowerFactor = 60f; public float criticalTacklePowerFactor = 60f;
[Tooltip("The power with which the character is tackled away, when hit normally.")] [Tooltip("The power with which the character is tackled away, when hit normally.")]

View File

@ -15,6 +15,8 @@ public class ShipProperties : ScriptableObject
public ShipInputHandler shipInput = null; public ShipInputHandler shipInput = null;
[Tooltip("Name of the ship (relevant to UI and lore context).")] [Tooltip("Name of the ship (relevant to UI and lore context).")]
public string shipName = "SpaceyMcShipface"; public string shipName = "SpaceyMcShipface";
[Tooltip("The main color of the ship.")]
public Color shipHullColor = Color.magenta;
[Tooltip("The acceleration applied on thrust input.")] [Tooltip("The acceleration applied on thrust input.")]
[Range(0.0f, 2.0f)] [Range(0.0f, 2.0f)]
@ -122,19 +124,33 @@ public class ShipProperties : ScriptableObject
public float stunLooseControlFactor public float stunLooseControlFactor
{ get => baseProps.stunLooseControlFactor * stunLooseControlFactorModifier; } { get => baseProps.stunLooseControlFactor * stunLooseControlFactorModifier; }
[Tooltip("Time until the tackling player can be tackled again")]
[Range(0.0f, 2.0f)]
public float tacklingGraceTimeModifier = 1;
[HideInInspector]
public float tacklingGraceTime
{ get => baseProps.tacklingGraceTime * tacklingGraceTimeModifier; }
[Tooltip("Time until the tackled player can be tackled again")]
[Range(0.0f, 2.0f)]
public float tackledGraceTimeModifier = 1;
[HideInInspector]
public float tackledGraceTime
{ get => baseProps.tackledGraceTime * tackledGraceTimeModifier; }
[Tooltip("The time it takes for a critically stunned character to be controlable again.")] [Tooltip("The time it takes for a critically stunned character to be controlable again.")]
[Range(0.0f, 2.0f)] [Range(0.0f, 2.0f)]
public float tackleCriticalStunTimeModifier = 1; public float tackleCriticalStunTimeModifier = 1;
[HideInInspector] [HideInInspector]
public float tackleCriticalStunTime public float tackledCriticalStunTime
{ get => baseProps.tackleCriticalStunTime * tackleCriticalStunTimeModifier; } { get => baseProps.tackledCriticalStunTime * tackleCriticalStunTimeModifier; }
[Tooltip("The time it takes for a normally stunned character to be controlable again.")] [Tooltip("The time it takes for a normally stunned character to be controlable again.")]
[Range(0.0f, 2.0f)] [Range(0.0f, 2.0f)]
public float tackleBodyStunTimeModifier = 1; public float tackleBodyStunTimeModifier = 1;
[HideInInspector] [HideInInspector]
public float tackleBodyStunTime public float tackledBodyStunTime
{ get => baseProps.tackleBodyStunTime * tackleBodyStunTimeModifier; } { get => baseProps.tackledBodyStunTime * tackleBodyStunTimeModifier; }
[Tooltip("The power with which the character is tackled away, when hit critically.")] [Tooltip("The power with which the character is tackled away, when hit critically.")]
[Range(0.0f, 2.0f)] [Range(0.0f, 2.0f)]

View File

@ -4,14 +4,15 @@ using static AffectingForcesManager;
using ShipHandling; using ShipHandling;
using Managers; using Managers;
using Unity.Mathematics; using Unity.Mathematics;
using FishNet.Object;
using FishNet.Connection;
using FishNet.Example.ColliderRollbacks;
using FORGE3D; using FORGE3D;
using PrimeTween;
using log4net;
using System.Reflection;
public class Ship : NetworkBehaviour public class Ship : MonoBehaviour
{ {
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public int InstanceID { get; private set; } public int InstanceID { get; private set; }
public ShipProperties props; public ShipProperties props;
public ShipState state; public ShipState state;
@ -24,6 +25,7 @@ public class Ship : NetworkBehaviour
public ParticleSystem smokeTrailEffect; public ParticleSystem smokeTrailEffect;
public F3DFXController fireController; public F3DFXController fireController;
public MeshRenderer bodyMeshRenderer;
private AffectingForcesManager forceManager; private AffectingForcesManager forceManager;
private Rigidbody body; private Rigidbody body;
@ -33,6 +35,7 @@ public class Ship : NetworkBehaviour
private bool isCriticalTackle = false; private bool isCriticalTackle = false;
private bool isTackled = false; private bool isTackled = false;
private float tackledTime = 0f; private float tackledTime = 0f;
private Tween tackleIgnoreTween = new();
private bool isFiring = false; private bool isFiring = false;
// Current Zone the player occupies // Current Zone the player occupies
private Zone zone = Zone.NimbleZone; private Zone zone = Zone.NimbleZone;
@ -77,7 +80,8 @@ public class Ship : NetworkBehaviour
tackleDetectors = GetComponentsInChildren<TackleDetection>(); tackleDetectors = GetComponentsInChildren<TackleDetection>();
foreach (TackleDetection td in tackleDetectors) foreach (TackleDetection td in tackleDetectors)
{ {
td.TackleResponse.AddListener(StartTackleResponse); td.TackledResponse += TackledResponse;
td.TacklingResponse += TacklingResponse;
} }
} }
@ -85,7 +89,8 @@ public class Ship : NetworkBehaviour
{ {
foreach (TackleDetection td in tackleDetectors) foreach (TackleDetection td in tackleDetectors)
{ {
td.TackleResponse.RemoveAllListeners(); td.TackledResponse = null;
td.TacklingResponse = null;
} }
} }
@ -171,6 +176,7 @@ public class Ship : NetworkBehaviour
|| zone != Zone.NimbleZone) || zone != Zone.NimbleZone)
{ {
body.AddForce(boostedAcceleration, ForceMode.Acceleration); body.AddForce(boostedAcceleration, ForceMode.Acceleration);
} }
if (currentVelocity.magnitude >= props.absolutMaxVelocity && zone == Zone.NimbleZone) if (currentVelocity.magnitude >= props.absolutMaxVelocity && zone == Zone.NimbleZone)
{ {
@ -308,7 +314,10 @@ public class Ship : NetworkBehaviour
} }
/// <summary> /// <summary>
/// Logic which sets the isTackled state. /// Logic which sets the tackled member variables and
/// updates them over time.
/// State logic depends on these variables and is responsible
/// for certain tackle behavior.
/// </summary> /// </summary>
/// <param name="gotTackled">Use true to process a tackle hit</param> /// <param name="gotTackled">Use true to process a tackle hit</param>
void UpdateTackleResponse(bool gotTackled = false) void UpdateTackleResponse(bool gotTackled = false)
@ -316,8 +325,8 @@ public class Ship : NetworkBehaviour
if (gotTackled && !isTackled) if (gotTackled && !isTackled)
{ {
isTackled = true; isTackled = true;
tackledTime = isCriticalTackle ? props.tackleCriticalStunTime : tackledTime = isCriticalTackle ? props.tackledCriticalStunTime :
props.tackleBodyStunTime; props.tackledBodyStunTime;
return; return;
} }
tackledTime -= Time.deltaTime; tackledTime -= Time.deltaTime;
@ -330,29 +339,71 @@ public class Ship : NetworkBehaviour
} }
/// <summary> /// <summary>
/// Called by the collision regions which detect tackling. /// Disable tackle responeses for a given time
/// Adds resulting forces to the ship and intiates the tackle /// </summary>
/// response. async void TemporarilyIgnoreTackles(float duration)
{
if (tackleIgnoreTween.isAlive)
return;
tackleIgnoreTween = Tween.Delay(duration);
await tackleIgnoreTween;
}
private bool IgnoreTackle()
{
return tackleIgnoreTween.isAlive;
}
/// <summary>
/// Response logic if the ship is tackling an opponend.
/// </summary>
void TacklingResponse()
{
if (IgnoreTackle())
return;
Log.Debug($"{props.shipName} is tackling.");
TemporarilyIgnoreTackles(props.tacklingGraceTime);
}
/// <summary>
/// Called by the collision regions of the ship being tackled by an opponent.
/// Adds resulting forces to the ship and intiates the tackle response.
/// </summary> /// </summary>
/// <param name="tackleKind">Kind of the tackle. Depends on collision region.</param> /// <param name="tackleKind">Kind of the tackle. Depends on collision region.</param>
/// <param name="collider">Object which has collided with the collision region.</param> /// <param name="collider">Object which has collided with the collision region.</param>
void StartTackleResponse(TackleKind tackleKind, Collider collider) void TackledResponse(TackleKind tackleKind, Collider collider)
{ {
// TODO: The one who tackled first should be exempt from knockback in some way if (IgnoreTackle())
return;
TemporarilyIgnoreTackles(props.tackledGraceTime);
float tacklePowerFactor = props.criticalTacklePowerFactor; float tacklePowerFactor = props.criticalTacklePowerFactor;
if (tackleKind == TackleKind.Critical) if (tackleKind == TackleKind.IncomingCritical)
{ {
isCriticalTackle = true; isCriticalTackle = true;
Log.Debug($"{props.shipName} has been tackled critically.");
} }
else else if (tackleKind == TackleKind.IncomingNormal)
{ {
isCriticalTackle = false; isCriticalTackle = false;
tacklePowerFactor = props.normalTacklePowerFactor; tacklePowerFactor = props.normalTacklePowerFactor;
Log.Debug($"{props.shipName} has been tackled.");
} }
Vector3 colliderVelocity = collider.attachedRigidbody.velocity; Vector3 colliderVelocity = collider.attachedRigidbody.velocity;
Vector3 tackleDirection = transform.position - collider.transform.position; //Log.Debug("velocity " + colliderVelocity);
body.AddForce(colliderVelocity.magnitude * tackleDirection * tacklePowerFactor,
//Log.Debug("angle " + angle);
//Log.Debug("outvector " + outVector);
Vector3 force = colliderVelocity * tacklePowerFactor;
Vector3 resultForce = force / Math.Max(force.magnitude / 4000, 1);
resultForce = resultForce / Math.Max(0.001f, Math.Min(resultForce.magnitude / 500, 1));
Log.Debug(resultForce.magnitude);
body.AddForce(resultForce,
ForceMode.Acceleration); ForceMode.Acceleration);
UpdateTackleResponse(true); UpdateTackleResponse(true);
} }
@ -405,10 +456,12 @@ public class Ship : NetworkBehaviour
if (isTackled && !isCriticalTackle) if (isTackled && !isCriticalTackle)
{ {
BeingTackledSound.PlayAudio(false, true); BeingTackledSound.PlayAudio(false, true);
cameraOperator.ShakeCam(0.2f);
} }
if (isCriticalTackle) if (isCriticalTackle)
{ {
BeingCriticallyTackledSound.PlayAudio(false, true); BeingCriticallyTackledSound.PlayAudio(false, true);
cameraOperator.ShakeCam(0.4f);
} }
if (!isTackled) if (!isTackled)
{ {
@ -454,14 +507,5 @@ public class Ship : NetworkBehaviour
} }
} }
// private void Seeker()
// {
// var offset = Quaternion.Euler(UnityEngine.Random.onUnitSphere);
// F3DPoolManager.Pools["GeneratedPool"].Spawn(muzzle, transform.position + shootExitOffset);
// var newGO =
// F3DPoolManager.Pools["GeneratedPool"].Spawn(projectile, transform.position + shootExitOffset,
// offset * transform.localRotation, null).gameObject;
// F3DAudioController.instance.SeekerShot(transform.position);
// }
} }

View File

@ -1,3 +1,4 @@
using FishNet.Object.Prediction;
using UnityEngine; using UnityEngine;
namespace ShipHandling namespace ShipHandling
@ -17,4 +18,5 @@ namespace ShipHandling
public bool IsFrozen = false; public bool IsFrozen = false;
public bool reset = false; public bool reset = false;
} }
} }

View File

@ -1,3 +1,4 @@
using System;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
@ -7,7 +8,8 @@ using UnityEngine.Events;
public class TackleDetection : MonoBehaviour public class TackleDetection : MonoBehaviour
{ {
[SerializeField] private TackleKind tackleKind; [SerializeField] private TackleKind tackleKind;
public UnityEvent<TackleKind, Collider> TackleResponse; public Action<TackleKind, Collider> TackledResponse;
public Action TacklingResponse;
/// <summary> /// <summary>
/// Invokes the fitting tackle response on trigger entered. /// Invokes the fitting tackle response on trigger entered.
@ -15,12 +17,31 @@ public class TackleDetection : MonoBehaviour
/// <param name="collider"></param> /// <param name="collider"></param>
void OnTriggerEnter(Collider collider) void OnTriggerEnter(Collider collider)
{ {
if (collider.tag != "Spike" && collider.tag != "Bumper") if (!(collider.tag == "Spike" ||
collider.tag == "Bumper" ||
collider.tag == "Vulnerable"))
{ {
return; return;
} }
TackleResponse.Invoke(tackleKind, collider);
switch (collider.tag)
{
case "Spike":
// Critical for weak spots
TackledResponse.Invoke(tackleKind, collider);
break;
case "Bumper":
// Always normal tackle
TackledResponse.Invoke(TackleKind.IncomingNormal, collider);
break;
case "Vulnerable":
if (tackleKind == TackleKind.OutgoingCritical ||
tackleKind == TackleKind.OutgoingNormal)
TacklingResponse.Invoke();
break;
}
} }
} }
public enum TackleKind { Critical, Normal } public enum TackleKind { IncomingCritical, IncomingNormal, OutgoingCritical, OutgoingNormal }