Physics2D/RigidBody2D: Use kinematic object instead of static ones when mass is set to zero

This commit is contained in:
Jérôme Leclercq 2017-09-01 13:34:04 +02:00
parent 092720b1d0
commit c087003bda
1 changed files with 2 additions and 4 deletions

View File

@ -274,13 +274,13 @@ namespace Nz
}); });
} }
else else
m_world->RegisterPostStep(this, [](Nz::RigidBody2D* body) { cpBodySetType(body->GetHandle(), CP_BODY_TYPE_STATIC); } ); m_world->RegisterPostStep(this, [](Nz::RigidBody2D* body) { cpBodySetType(body->GetHandle(), CP_BODY_TYPE_KINEMATIC); } );
} }
else if (mass > 0.f) else if (mass > 0.f)
{ {
m_world->RegisterPostStep(this, [mass](Nz::RigidBody2D* body) m_world->RegisterPostStep(this, [mass](Nz::RigidBody2D* body)
{ {
if (cpBodyGetType(body->GetHandle()) == CP_BODY_TYPE_STATIC) if (cpBodyGetType(body->GetHandle()) == CP_BODY_TYPE_KINEMATIC)
{ {
cpBodySetType(body->GetHandle(), CP_BODY_TYPE_DYNAMIC); cpBodySetType(body->GetHandle(), CP_BODY_TYPE_DYNAMIC);
cpBodySetMass(body->GetHandle(), mass); cpBodySetMass(body->GetHandle(), mass);
@ -309,8 +309,6 @@ namespace Nz
void RigidBody2D::SetPosition(const Vector2f& position) void RigidBody2D::SetPosition(const Vector2f& position)
{ {
cpBodySetPosition(m_handle, cpv(position.x, position.y)); cpBodySetPosition(m_handle, cpv(position.x, position.y));
if (cpBodyGetType(m_handle) == CP_BODY_TYPE_STATIC)
cpSpaceReindexShapesForBody(m_world->GetHandle(), m_handle);
} }
void RigidBody2D::SetRotation(float rotation) void RigidBody2D::SetRotation(float rotation)