Exemplo n.º 1
0
void Body::UpdateHitBox()
{
	if ( !m_hHitBox ) return;

    CCharacterHitBox* pHitBox = (CCharacterHitBox*) g_pLTServer->HandleToObject(m_hHitBox);
	if ( pHitBox )
	{
		pHitBox->Update();
	}
}
Exemplo n.º 2
0
void Body::Update()
{
	if ( !m_hObject ) return;

    LTVector vPos, vMin, vMax;
    g_pLTServer->GetWorldBox(vMin, vMax);
    g_pLTServer->GetObjectPos(m_hObject, &vPos);

	if (vPos.x < vMin.x || vPos.y < vMin.y || vPos.z < vMin.z ||
		vPos.x > vMax.x || vPos.y > vMax.y || vPos.z > vMax.z)
	{
		RemoveObject();
	}


	// Update the animator

	m_Animator.Update();

	// Make sure our hit box is in the correct position...

	UpdateHitBox();

	if ( m_bFirstUpdate )
	{
		m_bFirstUpdate = LTFALSE;
		m_fStartTime   = g_pLTServer->GetTime();
	}

	SetNextUpdate(s_fUpdateDelta);

	// We keep the body active to update dims for 2.0 seconds

	LTBOOL bUpdatingDims = g_pLTServer->GetTime() < m_fStartTime + 2.0f;

	// The deactivate-check, update, activate-check is ordered so that
	// deactivation will always happen one update after you enter a state,
	// but activation will always happen when you just entered the state.
	// This avoids a lot of issues with changing between active/inactive states.

	if ( !bUpdatingDims && (!m_pState || m_pState->CanDeactivate()) )
	{
		// Finalize the dims of our hit box...

		if (m_hHitBox)
		{
			CCharacterHitBox* pHitBox = (CCharacterHitBox*) g_pLTServer->HandleToObject(m_hHitBox);
			if ( pHitBox )
			{
				// For now just make the hit box 50% larger than our dims...

				LTVector vDims, vNewDims;
				g_pLTServer->GetObjectDims(m_hHitBox, &vDims);
				vNewDims = vDims;
				vNewDims.x *= 3.0f;
				vNewDims.z *= 3.0f;

				// Update 1.003, some cases the dims can get weird, not
				// sure why...Just make sure they are reasonable...
				if (vNewDims.x <= 0.0f || vNewDims.x > 75.0f)
				{
					vNewDims.x = 75.0f;
				}
				if (vNewDims.z <= 0.0f || vNewDims.z > 75.0f)
				{
					vNewDims.z = 75.0f;
				}

				// Only shrink us down if we're not sitting or stuck to a wall

				if ( m_eBodyStatePrevious == eBodyStateChair )
				{
				}
				else if ( m_eBodyStatePrevious == eBodyStateArrow )
				{
				}
				else
				{
					vNewDims.y = 15.0f;
				}

				g_pLTServer->SetObjectDims(m_hHitBox, &vNewDims);

				LTVector vOffset(0, vNewDims.y - vDims.y, 0);
				pHitBox->SetOffset(vOffset);
				pHitBox->Update();
			}
		}

		SetNextUpdate(0.0f);
	}

	if ( m_pState )
	{
		m_pState->Update();
	}

	if ( bUpdatingDims || (m_pState && !m_pState->CanDeactivate()) )
	{
	    SetNextUpdate(s_fUpdateDelta);
	}
}