Improve box collider creation behavior to account for child actors of the collider's parent.
This commit is contained in:
@@ -1,16 +1,39 @@
|
||||
using System;
|
||||
using FlaxEditor.Windows;
|
||||
|
||||
namespace FlaxEngine
|
||||
{
|
||||
partial class BoxCollider
|
||||
{
|
||||
private void BoxExcluding(Actor target, ref BoundingBox output, Actor excluded)
|
||||
{
|
||||
foreach (Actor child in target.Children)
|
||||
{
|
||||
if (child == excluded)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
output = BoundingBox.Merge(output, child.Box);
|
||||
BoxExcluding(child, ref output, excluded);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnActorSpawned()
|
||||
{
|
||||
base.OnActorSpawned();
|
||||
Vector3 parentScale = Parent.Scale;
|
||||
Vector3 parentSize = Parent.Box.Size;
|
||||
Vector3 parentCenter = Parent.Box.Center - Parent.Position;
|
||||
BoundingBox parentBox = Parent.Box;
|
||||
BoxExcluding(Parent, ref parentBox, this);
|
||||
|
||||
Vector3 parentSize = parentBox.Size;
|
||||
Vector3 parentCenter = parentBox.Center - Parent.Position;
|
||||
|
||||
// Avoid division by zero
|
||||
if (parentScale.X == 0 || parentScale.Y == 0 || parentScale.Z == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Size = parentSize / parentScale;
|
||||
Center = parentCenter / parentScale;
|
||||
|
||||
Reference in New Issue
Block a user