Example #1
0
void ApplyPushPull(PhysXObject* object)
{
    DisableGravity(object->actor);

    ApplyGravity(object->actor, planetTransforms[0].p, -WEAK_UNIVERSAL_GRAVITATIONAL_FORCE);
    ApplyGravity(object->actor, planetTransforms[2].p, STRONG_UNIVERSAL_GRAVITATIONAL_FORCE);
}
Example #2
0
bool CASW_Simple_Alien::PerformMovement(float deltatime)
{
	if (!m_bMoving)
		return false;

	if (m_hMoveTarget.Get())	// if we're moving to a specific object, update our target vector with its current location
	{
		m_vecMoveTarget = m_hMoveTarget->GetAbsOrigin();
	}
	Vector vecStartDiff = m_vecMoveTarget - GetAbsOrigin();
	vecStartDiff.z = 0;

	// check we're not there already
	if (vecStartDiff.Length2D() <= m_fArrivedTolerance)
	{
		FinishedMovement();
		return true;
	}
	
	// work out the new position we want to be in
	Vector vecDir = vecStartDiff;
	vecDir.NormalizeInPlace();
	//Msg("moving with delta %f\n", delta);
	Vector vecNewPos = GetAbsOrigin() + vecDir * GetIdealSpeed() * deltatime;
	if (TryMove(GetAbsOrigin(), vecNewPos, deltatime))
	{
		// apply gravity to our new position
		ApplyGravity(vecNewPos, deltatime);

		// we moved (at least some portion, maybe all)
		UTIL_SetOrigin(this, vecNewPos);

		// check if we're close enough, or have gone past, the move target
		Vector vecEndDiff = m_vecMoveTarget - GetAbsOrigin();
		vecEndDiff.z = 0;
		if (vecStartDiff.Dot(vecEndDiff) < 0 || vecEndDiff.Length2D() <= m_fArrivedTolerance)
		{
			// we've arrived
			FinishedMovement();
		}
		return true;
	}
	else
	{
		vecNewPos = GetAbsOrigin();
		if (ApplyGravity(vecNewPos, deltatime))	// if we failed to move forward, make sure gravity is still applied
		{
			// we moved (at least some portion, maybe all)
			UTIL_SetOrigin(this, vecNewPos);
		}
	}
	
	FailedMove();
	return false;
}
void EnemyGMonsterFire::processUpdate()
{
	BelowFeetLadderCheck();

	/* Stop All Directional Movement */
	if(!ipFlags.S_ON_GROUND) ApplyGravity();

	/* Check for End of Death Animation */
	if((player_spr->GetFrameSet() == ENEMY_FIRE_MONSTER_DEATH) && !player_spr->IsAnimating())
		Die();

	/* Check for end of an attack state */
	if(ipFlags.S_ATTACK)
		if((player_spr->GetFrameSet() == ENEMY_FIRE_MONSTER_ATTACK) && !player_spr->IsAnimating())
		{
			ipFlags.S_ATTACK = false;
			SetAnimation(ENEMY_FIRE_MONSTER_ATTACK, 0, false, false, 0, true);
		}
//	else
//		SetAnimation(ENEMY_FIRE_MONSTER_ATTACK, 0, false, false, 0, true);
	
	if(!ipFlags.S_DAMAGED && !ipFlags.S_ATTACK)
		switch(ipFlags.CurMState)
		{
			case move_stop:
				stop();
				break;

			default:
				break;
		}

	/* Center (0,0), offset by Render Offset */
//	SetRectangle(rectWorldLoc, 45, 45, -nxOffSet, -15);
}
Example #4
0
void EnemyPunk::processUpdate()
{
//	BelowFeetLadderCheck();

	/* Stop All Directional Movement */
	if(!ipFlags.S_ON_GROUND) ApplyGravity();
	else if(ipFlags.S_DAMAGED) StopMovement();

	/* Check for End of Death Animation */
	if((player_spr->GetFrameSet() == ENEMY_PUNK_ANIM_DEATH) && !player_spr->IsAnimating())
		Die();

	/* Check for end of an attack state */
	if(ipFlags.S_ATTACK)
		if((player_spr->GetFrameSet() == ENEMY_PUNK_ANIM_JUMP) && !player_spr->IsAnimating())
		{
			SetAnimation(ENEMY_PUNK_ANIM_STAND, 0, true, false, 10, false);

			ipFlags.S_JUMP = false;
			ipFlags.S_ATTACK = false;
		}

	if(!ipFlags.S_DAMAGED && !ipFlags.S_ATTACK)
		switch(ipFlags.CurMState)
		{
			case move_stop:
				stop();
				break;

			default:
				break;
		}

	//SetRectangle(rectWorldLoc, 25, 40, -nOffSet, -10);
}
//--------------------------------------------------------------------------------
void CObjCHAR_Collision::UpdatePositionAfterNonCollision ( void )
//--------------------------------------------------------------------------------
{
	ApplyGravity();

	if (m_vNext.z < m_fTerrainHeight) {
		m_vNext.z = m_fTerrainHeight;
	}
	m_pObj->ResetCUR_POS( m_vNext );	
}	
void SSParticles::UpdateUserLayer( const float deltaTime ) {
	int ParticleCount = 0;
	for (int i = 0; i < MAX_PARTICLE_BLOCKS; i++) {
		if (m_ParticleBlocks[i].IsActive) {
			for (int k = 0; k < PARTICLE_BLOCK_COUNT; k++) {
				glm::vec4 temp = m_ParticleBlocks[i].Particles[k].VelocityTTL;
				m_ParticleBlocks[i].Particles[k].Pos += glm::vec4(temp.x, temp.y, temp.z, 0) * 0.05f * deltaTime;

				ApplyGravity(m_ParticleBlocks[i].Particles[k]);
				if (glm::any(glm::greaterThan(glm::abs(m_ParticleBlocks[i].Particles[k].Pos), glm::vec4(1, 1, 1, 10)))) {
					m_ParticleBlocks[i].Particles[k].VelocityTTL *= -1;
				}
			}
			//kill particle blocks
			m_ParticleBlocks[i].TTL -= deltaTime;
			if (m_ParticleBlocks[i].TTL <= 0) {
				m_ParticleBlocks[i].IsActive = false;
				DeallocateParticles(m_ParticleBlocks[i].Particles);
				m_ParticleBlocks[i].Particles = nullptr;
				//printf("Killed a block of particles\n");
			}
		}
	}
	//spawn more particles
	m_SpawnTimer += deltaTime;
	float test = BLOCK_SPAWN_TIME;
	if (m_SpawnTimer > BLOCK_SPAWN_TIME) {
		for (int i = 0; i < BLOCK_SPAWN_AMOUNT; i++)
			SpawnBlock();
		m_SpawnTimer = 0;
	}
	//update vertex buffer
	glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
	for (int i = 0; i < MAX_PARTICLE_BLOCKS; i++) {
		if (m_ParticleBlocks[i].IsActive) {
			glBufferSubData(GL_ARRAY_BUFFER, i * PARTICLE_BLOCK_SIZE, PARTICLE_BLOCK_SIZE, m_ParticleBlocks[i].Particles);
			ParticleCount += PARTICLE_BLOCK_COUNT;
		}
	}
	glBindVertexArray(m_VAO);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	m_RenderProgram.Apply();
	glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
	glBindVertexArray(m_VAO);
	glPointSize(1.0f);
	glDrawArrays(GL_POINTS, 0, ParticleCount);

	//profiling
	m_ProfileTimer += deltaTime;
	if (m_ProfileTimer > 5) {
		Profiler::ProfilerManager::GetInstance().PrintAveragesMilliSeconds();
		m_ProfileTimer = 0;
	}
	Profiler::ProfilerManager::GetInstance().ResetFrame();
}
Example #7
0
void Bejeweled::Update() {
	if(FindCombos()) {
		multiplier++;
		ApplyGravity();
		
		// Update when everyone is done moving
		new Timer(AnimateSpeed * 1200,true,TimerUpdate);
	} else {
		multiplier = 1;
	}
}
Example #8
0
void Vertex::UpdateVertex(float deltaTime, float volumeCompensatCoe, float contactAngle)
{
	UpdateNormal();
	UpdateCoverArea();
	
	if(!isOnASurface)
		ApplyVolumeCompensation(volumeCompensatCoe, deltaTime);
	if(!isOnASurface)
		ApplyGravity(deltaTime);
	//if(!isOnASurface)
		ApplySurfaceTension(deltaTime);
	ApplyRestrict(contactAngle);
}
Example #9
0
	void CTetris::ProcessGameRunning(double dt)
	{
		m_timeSinceGravity += dt;

		if (m_timeSinceGravity < GRAVITYTIME)
		{
			if (!m_forceGravity)
				return;
			else if (m_timeSinceGravity < (GRAVITYTIME / 20.0f))
				return;
		}


		if (LockCheck())
		{
			LockCurBrick();
			delete m_curBrick;
			m_curBrick = nullptr;
		}
		else
			ApplyGravity();

		if (!GetCurBrick())
		{
			delete m_curBrick;
			m_curBrick = nullptr;
			CheckDeleteFilledRows();
			m_curBrick = CreateRandomBrick();
			if (IsFail())
			{
				EndGame();
				SetGameOver();
			}
		}

		// Even if gravity wasn't applied, we set it to 0,
		// because a new brick would been created if Gravity never
		// got applied, and we want the timer to start over.
		m_timeSinceGravity = 0;
	}
Example #10
0
    void PhysicsWorld::ExecFrame()
    {
        LockThread();
    //
    //  [disabled] Lock timestep to improve collision prediction
        //m_QueuedTime += (GFloat)rsk::gClock->GetFrameTimeSeconds();
    //
    //  [enabled] Try to normalize the timestep to improve collision prediction
        m_FrameTime += (GFloat)rsk::gClock->GetFrameTimeSeconds();
        m_FrameTime *= 0.5f;
//        if( m_QueuedTime >= m_FrameTime )
        {
            CheckCollisions();
            HandleCollisions();
            ApplyGravity();

            RSKMAP_ITERATE( m_Entities )
                iter->second->ExecFrame( m_FrameTime );

//            m_QueuedTime = 0.f;
        }
    }
Example #11
0
/*************************************************************************************************************
UPDATES KINETMATICS/POSITION: Velocity, Acceleration, Force, Position
*************************************************************************************************************/
void PhysicsComponent::Update(float dt)
{
	if (!isActive)
		return;

	//Calculate New Acceleration/Velocity
	this->v_Acceleration = this->v_Force / mass;
	this->v_Velocity = v_Velocity + v_Acceleration;

	//Limit
	if ((fabs)(v_Velocity.x) >= MAX_VELOCITY)
		v_Velocity.x = ((fabs)(v_Velocity.x) / v_Velocity.x) * MAX_VELOCITY;
	if ((fabs)(v_Velocity.y) >= MAX_VELOCITY)
		v_Velocity.y = ((fabs)(v_Velocity.y) / v_Velocity.y) * MAX_VELOCITY;

	if ((fabs)(v_Acceleration.x) >= MAX_ACCELERATION)
		v_Acceleration.x = ((fabs)(v_Acceleration.x) / v_Acceleration.x) * MAX_ACCELERATION;
	if ((fabs)(v_Acceleration.y) >= MAX_ACCELERATION)
		v_Acceleration.y = ((fabs)(v_Acceleration.y) / v_Acceleration.y) * MAX_ACCELERATION;

	/***************************************************************************************************************************
	Horizontal Force
	****************************************************************************************************************************/
	if (hasFriction)
		ApplyFriction();

	/***************************************************************************************************************************
	Vertical Force
	****************************************************************************************************************************/
	if (hasGravity)
		ApplyGravity();

	//Update Velocity and Position
	v_Force.SetZero();
	v_Velocity = v_Velocity + v_Acceleration;


	*v_Pos = (*v_Pos) + v_Velocity * dt;
}
// Called every frame
void UCustomMovementComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// Stop if CapsuleComponet is invalid
	if (CapsuleComponent == NULL)
	{
		return;
	}

	// Update CurrentTraceShapeScale
	if (CurrentTraceShapeScale != TraceShapeScale)
	{
		CurrentTraceShapeScale = FMath::Clamp<float>(TraceShapeScale, 0.0f, 1.0f - KINDA_SMALL_NUMBER);
	}

	/* Local Variables */
	const EDrawDebugTrace::Type DrawDebugType = bDebugIsEnabled ? DebugDrawType : EDrawDebugTrace::None;
	const ECollisionChannel CollisionChannel = CapsuleComponent->GetCollisionObjectType();
	const FVector TraceStart = CapsuleComponent->GetComponentLocation();
	const float CapsuleHalfHeight = CapsuleComponent->GetScaledCapsuleHalfHeight();
	float ShapeRadius = CapsuleComponent->GetScaledCapsuleRadius() * 0.99f;
	FVector TraceEnd = TraceStart - CapsuleComponent->GetUpVector()* (CapsuleHalfHeight - ShapeRadius + GroundHitToleranceDistance + 1.0f);
	FHitResult HitResult;
	TArray<AActor*> ActorsToIgnore;

	
#pragma region Standing/Falling Definition

	/** Testing if the Capsule is in air or standing on a walkable surface*/

	UKismetSystemLibrary::SphereTraceSingle_NEW(this, TraceStart, TraceEnd, ShapeRadius, 
		UEngineTypes::ConvertToTraceType(TraceChannel), true, ActorsToIgnore, DrawDebugType, HitResult, true);
	bIsInAir = !HitResult.bBlockingHit;
	TimeInAir = bIsInAir ? TimeInAir + DeltaTime : 0.0f;
	CurrentStandingSurface = HitResult;

#pragma endregion

#pragma region Update Capsule linearDamping
	/**
	* Update Capsule linearDamping
	* If Grounded L-D is set to 1.0f , in same cases helps to stop the capsule when we are not moving
	* If falling case , stetting L-D to 0.01f , Helps to reach the wanted jump height when JumpImpulse is applied
	*/

	if (CapsuleComponent->GetLinearDamping() != 0.01f && bIsInAir)
	{
		CapsuleComponent->SetLinearDamping(0.01f);
	}
	else if (CapsuleComponent->GetLinearDamping() != 1.0f && !bIsInAir)
	{
		CapsuleComponent->SetLinearDamping(1.0f);
	}
	else if (TimeInAir > 1.0f && PlanetActor != nullptr && !bIsJumping)
	{
		CapsuleComponent->SetLinearDamping(0.5f);
	}
#pragma endregion

#pragma region Gravity Settings

	/*  Gravity Settings : Update Current Gravity info*/

	if (bResetVelocityOnGravitySwitch)
	{
		if (bIsInAir && bCanResetGravity && TimeInAir >= GravitySwitchDelay)
		{
			StopMovementImmediately();
			bCanResetGravity = false;
		}
		else if (!bIsInAir && !bCanResetGravity)
		{
			bCanResetGravity = true;
		}
	}


	if (!bIsInAir && StandingVerticalOrientation == EVerticalOrientation::EVO_SurfaceNormal)
	{

		if (bUseCapsuleHit)
		{
			if (CapsuleHitResult.IsValidBlockingHit())
			{
				CurrentTracedSurface = CapsuleHitResult;
			}
		}

		else
		{
			ShapeRadius = CapsuleComponent->GetScaledCapsuleRadius() * CurrentTraceShapeScale;
			TraceEnd = TraceStart - CapsuleComponent->GetUpVector()* (CapsuleHalfHeight + GroundHitToleranceDistance + 1.0f);

			if (TraceShape == ETraceShape::ETS_Line)
			{
				UKismetSystemLibrary::LineTraceSingle_NEW(this, TraceStart, TraceEnd, 
					UEngineTypes::ConvertToTraceType(TraceChannel), true, ActorsToIgnore, DrawDebugType, HitResult, true);
			}
			else if (TraceShape == ETraceShape::ETS_Sphere)
			{
				TraceEnd += CapsuleComponent->GetUpVector() * ShapeRadius;
				UKismetSystemLibrary::SphereTraceSingle_NEW(this, TraceStart, TraceEnd, ShapeRadius, 
					UEngineTypes::ConvertToTraceType(TraceChannel), true, ActorsToIgnore, DrawDebugType, HitResult, true);
			}
			else
			{
				TraceEnd += CapsuleComponent->GetUpVector() * ShapeRadius;
				UKismetSystemLibrary::BoxTraceSingle(this, TraceStart, TraceEnd, FVector(1, 1, 1)*ShapeRadius, CapsuleComponent->GetComponentRotation(),
					UEngineTypes::ConvertToTraceType(TraceChannel), true, ActorsToIgnore, DrawDebugType, HitResult, true);
			}

			CurrentTracedSurface = HitResult;

		}
		const bool bOnWalkableSurface = CurrentTracedSurface.IsValidBlockingHit();


		if (bOnWalkableSurface)
		{
			SurfaceBasedGravityInfo.GravityDirection = -HitResult.ImpactNormal;
			CurrentGravityInfo = SurfaceBasedGravityInfo;
			CurrentOrientationInfo = OrientationSettings.SurfaceBasedGravity;
		}

	}

	else if ((!bIsInAir && StandingVerticalOrientation == EVerticalOrientation::EVO_GravityDirection) ||
		(bIsInAir && FallingVerticalOrientation == EVerticalOrientation::EVO_GravityDirection))
	{

		if (!bIsInAir || TimeInAir > GravitySwitchDelay)
		{

			switch (CustomGravityType)
			{


			case EGravityType::EGT_Default:
			{
				if (CapsuleComponent->IsGravityEnabled() && GravityScale == 0)
				{
					CapsuleComponent->SetEnableGravity(false);
					CapsuleComponent->SetAllPhysicsLinearVelocity(FVector::ZeroVector);
				}
				else if (!CapsuleComponent->IsGravityEnabled() && GravityScale != 0)
				{
					CapsuleComponent->SetEnableGravity(true);
				}

				CurrentGravityInfo = FGravityInfo(-CapsuleComponent->GetWorld()->GetGravityZ(), -FVector::UpVector, EForceMode::EFM_Acceleration, true);
				CurrentOrientationInfo = OrientationSettings.DefaultGravity;

				UpdateCapsuleRotation(DeltaTime, -CurrentGravityInfo.GravityDirection, CurrentOrientationInfo.bIsInstant, CurrentOrientationInfo.RotationInterpSpeed);

				return;
			}


			case EGravityType::EGT_Custom:
			{
				CurrentGravityInfo = CustomGravityInfo;
				CurrentOrientationInfo = OrientationSettings.CustomGravity;
				break;
			}


			case EGravityType::EGT_GlobalCustom:
			{
				CurrentGravityInfo = UCustomGravityManager::GetGlobalCustomGravityInfo();
				CurrentOrientationInfo = OrientationSettings.GlobalCustomGravity;
				break;
			}


			case EGravityType::EGT_Point:
			{
				if (PlanetActor == NULL) { return; }
				CurrentGravityInfo = PlanetActor->GetGravityinfo(CapsuleComponent->GetComponentLocation());
				CurrentOrientationInfo = OrientationSettings.PointGravity;
				break;
			}
			}
		}
	}

#pragma endregion


	
	/** Variables definition & initialization */
	const FVector CurrentGravityDirection = CurrentGravityInfo.GravityDirection;
	const bool bUseAccelerationChange = (CurrentGravityInfo.ForceMode == EForceMode::EFM_Acceleration);
	const bool bShouldUseStepping = CurrentGravityInfo.bForceSubStepping;
	const float CurrentGravityPower = CurrentGravityInfo.GravityPower * GravityScale;

	const FVector GravityForce = CurrentGravityDirection.GetSafeNormal() * CurrentGravityPower;

	const float InterpSpeed = CurrentOrientationInfo.RotationInterpSpeed;
	const bool bOrientationIsInstant = CurrentOrientationInfo.bIsInstant;

	/* Update Rotation : Orient Capsule's up vector to have the same direction as -gravityDirection */
	UpdateCapsuleRotation(DeltaTime, -CurrentGravityDirection, bOrientationIsInstant, InterpSpeed);

	/* Apply Gravity*/
	ApplyGravity(GravityForce, bShouldUseStepping, bUseAccelerationChange);
}