私はある種の XNA ゲーム フレームワークに取り組んでいます。これに関する私の現在のプロジェクトは、衝突の検出/解決に関するものです。衝突検出の半作業方法があります。しかし、私の問題は方向衝突にあります。右側など、別のオブジェクトがこのオブジェクトに衝突しているかどうかを確認できるようにしたいと考えています。
しかし、私の問題は、衝突をどのように解決しても、自分の下にある別のオブジェクトの内側で立ち往生し、その結果、右側でも衝突したと見なされることです。
これが少し漠然とした質問であることは承知していますが、数日間これを理解しようとしてきましたが、解決策は見つかりませんでした.
何か案は?
public ICollidable IsCollidedOnLeftAny()
{
return (from ICollidable collidable in ParentObject.ParentState.ObjectList where collidable.GetCollidableComponent() != this where IsCollidedOnRight(collidable) select collidable).FirstOrDefault();
}
public bool IsCollidedWithObject(ICollidable collidable, CollisionMode mode)
{
if (IsGhost || collidable.GetCollidableComponent().IsGhost) return false;
switch (mode)
{
case CollisionMode.BoundingCircle:
var distanceVector = collidable.GetTransformComponent().Position - ParentObject.Transform.Position;
return distanceVector.Length() <= BoundingCircleRadius + collidable.GetCollidableComponent().BoundingCircleRadius;
case CollisionMode.BoundingRectangle:
return BoundingRectangle.Intersects(collidable.GetCollidableComponent().BoundingRectangle);
}
return false;
}
public bool IsCollidedOnLeft(ICollidable collidable) // Is this object collided on ITS OWN LEFT SIDE with the given object?
{
return BoundingRectangle.Right > collidable.GetCollidableComponent().BoundingRectangle.Left && !(BoundingRectangle.Left > collidable.GetCollidableComponent().BoundingRectangle.Left) && IsCollidedWithObject(collidable, CollisionMode.BoundingRectangle);
}
判読できない大量のコードで申し訳ありませんが、それを説明するより良い方法を知りません。