Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 34 additions & 36 deletions Content.Shared/StepTrigger/StepTriggerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,62 +18,60 @@ public override void Initialize()

public override void Update(float frameTime)
{
foreach (var (_, trigger) in EntityQuery<StepTriggerActiveComponent, StepTriggerComponent>())
foreach (var (_, trigger, transform) in EntityQuery<StepTriggerActiveComponent, StepTriggerComponent, TransformComponent>())
{
if (!Update(trigger))
if (!Update(trigger, transform))
continue;

RemComp<StepTriggerActiveComponent>(trigger.Owner);
}
}

private bool Update(StepTriggerComponent component)
private bool Update(StepTriggerComponent component, TransformComponent transform)
{
if (component.Deleted || !component.Active || component.Colliding.Count == 0)
if (!component.Active ||
component.Colliding.Count == 0)
return true;


foreach (var otherUid in component.Colliding.ToArray())
{
if (!otherUid.IsValid())
{
component.Colliding.Remove(otherUid);
component.CurrentlySteppedOn.Remove(otherUid);
component.Dirty();
continue;
}

// TODO: This shouldn't be calculating based on world AABBs.
var ourAabb = _entityLookup.GetWorldAABB(component.Owner);
var otherAabb = _entityLookup.GetWorldAABB(otherUid);
var shouldRemoveFromColliding = UpdateColliding(component, transform, otherUid);
if (!shouldRemoveFromColliding) continue;

if (!TryComp(otherUid, out PhysicsComponent? otherPhysics) || !ourAabb.Intersects(otherAabb))
{
component.Colliding.Remove(otherUid);
component.CurrentlySteppedOn.Remove(otherUid);
component.Dirty();
continue;
}
component.Colliding.Remove(otherUid);
component.CurrentlySteppedOn.Remove(otherUid);
Dirty(component);
}
return false;
}

if (component.CurrentlySteppedOn.Contains(otherUid))
continue;
private bool UpdateColliding(StepTriggerComponent component, TransformComponent ownerTransform, EntityUid otherUid)
{
if (!TryComp(otherUid, out PhysicsComponent? otherPhysics))
return true;

if (!CanTrigger(component.Owner, otherUid, component))
continue;
if (component.CurrentlySteppedOn.Contains(otherUid) ||
!CanTrigger(component.Owner, otherUid, component) ||
otherPhysics.LinearVelocity.Length < component.RequiredTriggerSpeed)
return false;

if (otherPhysics.LinearVelocity.Length < component.RequiredTriggerSpeed)
continue;
// TODO: This shouldn't be calculating based on world AABBs.
var ourAabb = _entityLookup.GetWorldAABB(component.Owner, ownerTransform);
var otherAabb = _entityLookup.GetWorldAABB(otherUid);

var percentage = otherAabb.IntersectPercentage(ourAabb);
if (percentage < component.IntersectRatio)
continue;
if (!ourAabb.Intersects(otherAabb))
return true;

var ev = new StepTriggeredEvent { Source = component.Owner, Tripper = otherUid };
RaiseLocalEvent(component.Owner, ref ev);
var percentage = otherAabb.IntersectPercentage(ourAabb);
if (percentage < component.IntersectRatio)
return false;

component.CurrentlySteppedOn.Add(otherUid);
component.Dirty();
}
var ev = new StepTriggeredEvent { Source = component.Owner, Tripper = otherUid };
RaiseLocalEvent(component.Owner, ref ev);

component.CurrentlySteppedOn.Add(otherUid);
Dirty(component);
return false;
}

Expand Down