void PhysicsComponent::update(double delta) {

    timeDelta = delta;
    if (useGravity) applyGravity();
    if (useFriction) applyFriction();
    
    
    force = checkForce(force);
    
    movement = (impulse+force)*timeDelta;

    applyMove(movement, true);
    
    impulse = Vec2(0,0);

}
示例#2
0
void Racer::applyForces(float seconds)
{
	hkVector4 aVel, vel = body->getLinearVelocity();
	float dot = vel.dot3(vel);
	aVel = body->getAngularVelocity();
	float aDot = aVel.dot3(aVel);

	// Only want to be automatically braking if the player
	// isn't trying to move or already moving
	if (((dot > 0.0f) && (dot < 6.0f) && (aDot != 0.0f)) &&
		(currentAcceleration == 0.0f))
	{
		brake(seconds);
	}
	else
	{
		applyFriction(seconds);
	}

	applyTireRaycast();
	applySprings(seconds);
	applyDrag(seconds);
	

	if (laserTime > 0.0f)
	{
		laserTime -= seconds;
	}


	if (respawnTimer > 0.0f)
	{
		respawnTimer -= seconds;

		SmokeParticle* smoke = new SmokeParticle();
		hkVector4 pos = body->getPosition();
		smoke->setPosition(&pos);
		SmokeSystem::system->addSmoke(ROCKET_SMOKE, smoke);
		smoke = NULL;
	}
	else if (!respawned && (respawnTimer <= 0.0f))
	{
		respawnTimer = 0.0f;
		respawned = true;
		respawn();
	}
}
void Racer::applyForces(float seconds)
{
	applySprings(seconds);
	applyFriction(seconds);
}