Ship contact is a simulation rule: Zone steps Contacts, Unity physics writes no Entity
Contacts.Step exchanges normal velocity between touching hull discs (PostCollisionVelocity moved verbatim from ShieldManager) and publishes Zone.Contacted; ShieldManager presents it; HullCollider.OnCollisionEnter and ShieldManager's ship-on-ship branch are deleted. Not yet built or tested (verification follows). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
efee2a2adc
commit
7392bc8fe1
6 changed files with 363 additions and 26 deletions
|
|
@ -1,17 +1,12 @@
|
|||
using UnityEngine;
|
||||
using CultMath.UnityBridge;
|
||||
|
||||
// Cut 4 (docs/fire-control-cut.md): Hit, Splash, SendHit and SendSplash are deleted -- their last callers
|
||||
// (ConstantLaser, ConstantLightning, ConstantParticleWeapon, HitscanEffect) are gone too (see those
|
||||
// files and FireControl.Detonate, 12.4(b)'s renamed Splash). Nothing decides or applies damage through a Unity
|
||||
// collider any more (R8):
|
||||
// this component is now purely a physics surface for ship-on-ship collision impulse, not hit detection.
|
||||
// collider any more (R8), and no collision callback writes an Entity (cut sim-contact): ship contact is
|
||||
// Zone's, through Contacts.Step. This component holds the hull's collider for authoring, smokes and click
|
||||
// picking, and writes nothing.
|
||||
public class HullCollider : MonoBehaviour
|
||||
{
|
||||
public Entity Entity { get; set; }
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
Entity.Velocity += other.impulse.ToCultMath().xz / Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using CultMath;
|
||||
using CultMath.UnityBridge;
|
||||
using static CultMath.math;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShieldManager : MonoBehaviour
|
||||
|
|
@ -12,7 +13,29 @@ public class ShieldManager : MonoBehaviour
|
|||
public Prototype ShieldPrototype;
|
||||
public float CollisionHitDuration = 3;
|
||||
|
||||
public Entity Entity { get; set; }
|
||||
private Entity _entity;
|
||||
private IDisposable _contacts;
|
||||
|
||||
// Ship-on-ship contact is Zone's (Contacts.Step); this shield only presents it.
|
||||
public Entity Entity
|
||||
{
|
||||
get => _entity;
|
||||
set
|
||||
{
|
||||
_contacts?.Dispose();
|
||||
_entity = value;
|
||||
_contacts = value?.Zone.Contacted.Subscribe(Present);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy() => _contacts?.Dispose();
|
||||
|
||||
private void Present(ContactEvent contact)
|
||||
{
|
||||
if (contact.A != Entity && contact.B != Entity) return;
|
||||
if (Entity.Shield != null && Entity.Shield.Item.Active.Value)
|
||||
ShowHit(new Vector3(contact.Point.x, Entity.Position.y, contact.Point.y), CollisionHitDuration);
|
||||
}
|
||||
|
||||
private ShieldEnvelope _envelope;
|
||||
private bool _loggedMissingEnvelope;
|
||||
|
|
@ -60,24 +83,7 @@ public class ShieldManager : MonoBehaviour
|
|||
}
|
||||
else
|
||||
Debug.Log("Shield collision occurred, but other collider isn't a shield or a grid object!");
|
||||
return;
|
||||
}
|
||||
var contact = other.GetContact(0);
|
||||
var normal = normalize(float2(contact.normal.x, contact.normal.z));
|
||||
var tangent = normal.Rotate(ItemRotation.CounterClockwise);
|
||||
var v1n = dot(normal, Entity.Velocity);
|
||||
var v1t = dot(tangent, Entity.Velocity);
|
||||
var v2n = dot(normal, otherShield.Entity.Velocity);
|
||||
//var v2t = dot(tangent, otherShield.Entity.Velocity);
|
||||
|
||||
var v1np = PostCollisionVelocity(v1n, Entity.Mass, v2n, otherShield.Entity.Mass);
|
||||
Entity.Velocity = tangent * v1t + normal * v1np;
|
||||
if(Entity.Shield != null && Entity.Shield.Item.Active.Value) ShowHit(contact.point, CollisionHitDuration);
|
||||
}
|
||||
|
||||
private float PostCollisionVelocity(float v1, float m1, float v2, float m2)
|
||||
{
|
||||
return (v1 * (m1 - m2) + m2 * v2) / (m1 + m2);
|
||||
}
|
||||
|
||||
public void ShowHit(Vector3 point, float duration)
|
||||
|
|
|
|||
Loading…
Reference in a new issue