Пример #1
0
void CharacterObject::updateCharacter(float dt)
{
	/*
	 * You can fire weapons while moving
	 *
	 * Two Modes: Moving and Action
	 * Moving covers walking & jumping
	 * Action covers complex things like shooting, entering vehicles etc.
	 *
	 * Movement animation should be handled here
	 *  If Current weapon is one handed, then it can be used while walking.
	 *  This means blending the weapon animation with the walk animation.
	 *  No weapons can be used while sprinting.
	 *  Need an "aim vector" to apply torso correction.
	 *
	 *  If movement vector is less than some threshold, fully walk animation
	 *  (time adjusted for velocity).
	 */

	if(physCharacter) {
		glm::vec3 walkDir = updateMovementAnimation(dt);

		position = getPosition();

		if (canTurn()) {
			rotation = glm::angleAxis(m_look.x, glm::vec3{0.f, 0.f, 1.f});
		}

		walkDir = rotation * walkDir;

		if( jumped )
		{
			if( !isOnGround() )
			{
				walkDir = rotation * glm::vec3(0.f, jumpSpeed * dt, 0.f);
			}
		}

		if (isAlive())
		{
			physCharacter->setWalkDirection(btVector3(walkDir.x, walkDir.y, walkDir.z));
		}
		else
		{
			physCharacter->setWalkDirection(btVector3(0.f, 0.f, 0.f));
		}

		auto Pos = physCharacter->getGhostObject()->getWorldTransform().getOrigin();
		position = glm::vec3(Pos.x(), Pos.y(), Pos.z());

		// Handle above waist height water.
		auto wi = engine->data->getWaterIndexAt(getPosition());
		if( wi != NO_WATER_INDEX ) {
			float wh = engine->data->waterHeights[wi];
			auto ws = getPosition();
			wh += engine->data->getWaveHeightAt(ws);
			
			// If Not in water before
			//  If last position was above water
			//   Now Underwater
			//  Else Not Underwater
			// Else
			//  Underwater
			
			if( ! inWater && ws.z < wh && _lastHeight > wh ) {
				ws.z = wh;

				btVector3 bpos(ws.x, ws.y, ws.z);
				physCharacter->warp(bpos);
				auto& wt = physObject->getWorldTransform();
				wt.setOrigin(bpos);
				physObject->setWorldTransform(wt);

				physCharacter->setGravity(0.f);
				inWater = true;
			}
			else {
				physCharacter->setGravity(9.81f);
				inWater = false;
			}
		}
		_lastHeight = getPosition().z;
	}
	else
	{
		updateMovementAnimation(dt);
	}
}
Пример #2
0
void Cobra::setDirection(int direction) {
    if (canTurn(direction)) {
        inputDirection = direction;
    }
}