Home Game Development xna – Collision detection drawback in XNA4/Monogame

xna – Collision detection drawback in XNA4/Monogame

0
xna – Collision detection drawback in XNA4/Monogame

[ad_1]

Here’s one drawback:

bs1.Center += place;
bs2.Center +=entity.place;

But, you are additionally doing this in CreateBoundingSphereForModel():

return boundingSphere.Transform(getWorld());

So, you are reworking the sphere – which strikes it into world coordinates. Then, you are offsetting it is place based mostly on the entity’s rework. Basically, you are shifting the bounding sphere twice as removed from the origin because the entity. Get rid of the primary block (bs*.Center += entity.place) and see what occurs.

public bool intersects(ModelEntity entity)
{
    BoundingSphere bs1 = CreateBoundingSphereForModel();
    BoundingSphere bs2 = entity.CreateBoundingSphereForModel();

    return bs1.Intersects(bs2))
}

One different notice: Your getWorld() is doing issues within the mistaken order. Your strategy strikes the thing to its world place, then rotates it across the origin. Your sphere would wind up orbiting the origin fairly than spinning by itself axis.

In this framework, operations occur in SRT (scale, rotate, translate) order. (In OpenGL it will be the reverse.) So, it is best to have:

public Matrix getWorld()
{
    return  Matrix.CreateRotationY(rotation.Y) * Matrix.CreateRotationZ(rotation.Z) * Matrix.CreateRotationX(rotation.X) * Matrix.CreateTranslation(place);
}

Or, higher but, use CreateFromRollPitchYaw():

public Matrix getWorld()
{
    return Matrix.CreateFromRollPitchYaw(rotation.Z,rotation.X,rotation.Y) * Matrix.CreateTranslation(place);
}

… assuming that you do not wish to mess with quaternions which remove gimbal lock.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here