I have a problem with my collision/physics routine. It seems to work, but only when the ground object hasn't been moved. I have a sphere that's supposed to bounce off it and slide on it, but when I move the ground, it just seems to think it's still at (0, 0, 0).
Here is the code for the physics:
// Gravity
m_Frc[0] = Gravity * m_fMass;
// Total force
for ( size_t f = 0; f < m_Frc.size(); f++ )
m_FrcT = m_FrcT + m_Frc[f];
// Acceleration, Velocity, Drag
m_Acc = m_FrcT / m_fMass;
m_Vel = m_Vel + m_Acc;
m_Vel = m_Vel * m_fDrag;
// Position
m_Obj->Position( m_Obj->Pos() + m_Vel );
// Collision
DWORD Col = SC_SphereSlide(
0,
m_Obj->Pos().X() - m_Vel.X(),
m_Obj->Pos().Y() - m_Vel.Y(),
m_Obj->Pos().Z() - m_Vel.Z(),
m_Obj->Pos().X(),
m_Obj->Pos().Y(),
m_Obj->Pos().Z(),
m_Obj->Size().Z() * 0.5f,
m_Obj->ID()
);
if ( Col > 0 )
{
m_Obj->Position( Vector( SC_GetCollisionSlideX(), SC_GetCollisionSlideY(), SC_GetCollisionSlideZ() ) );
m_Vel = Vector( SC_GetCollisionBounceX(), SC_GetCollisionBounceY(), SC_GetCollisionBounceZ() );
}
Can anyone explain the problem?
Thanks
[edit]
OK, fixed the problem. Turns out I was positioning the object after I set it up, and didn't call SC_UpdateObject().
Thanks anyways guys