Exemple #1
0
void AWeapon::FireProjectile()
{
	FHitResult ObjectHit(EForceInit::ForceInit);
	FVector CameraLocation;
	FRotator CameraRotation;
	WeaponOwner->Controller->GetPlayerViewPoint(CameraLocation, CameraRotation);
	const FVector TraceStart = CameraLocation;
	const FVector TraceDirection = CameraRotation.Vector();

	FRandomStream WeaponRandomStream(FMath::Rand());
	const float SpreadCone = FMath::DegreesToRadians(Config.Spread * 0.5);
	const FVector ShotDirection = WeaponRandomStream.VRandCone(TraceDirection, SpreadCone, SpreadCone);
	const FVector TraceEnd = TraceStart + ShotDirection * Config.Range;

	FCollisionQueryParams TraceParams(FName(TEXT("TraceShot")), true, this);
	TraceParams.AddIgnoredActor(WeaponOwner);

	//Weapon Recoil Calculation
	WeaponOwner->AddControllerPitchInput(-(Config.Recoil));
	if (FMath::FRand() >= 0.65f)
	{
		WeaponOwner->AddControllerYawInput(Config.Recoil);
	}
	else
	{
		WeaponOwner->AddControllerYawInput(-(Config.Recoil));
	}

	const UWorld* World = GetWorld();

	//debug code start//////////////////////////////////

	if (GEngine)
	{
		//GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Yellow, ShotDirection.ToString());
	}

	DrawDebugLine(
		World,
		TraceStart,
		TraceEnd,
		FColor(255, 0, 0),
		false, 3, 0,
		3.0
		);

	//debug code end////////////////////////////////////

	bool HitDetected = false;
	if (World)
	{
		HitDetected = World->LineTraceSingle(ObjectHit, TraceStart, TraceEnd, ECollisionChannel::ECC_WorldDynamic, TraceParams);
		if (HitDetected)
		{
			DoDamage(ObjectHit);
		}
	}
}
void CBulletManager::RegisterEvent			(EventType Type, BOOL _dynamic, SBullet* bullet, const Fvector& end_point, collide::rq_result& R, u16 tgt_material)
{
	m_Events.push_back	(_event())		;
	_event&	E		= m_Events.back()	;
	E.Type			= Type				;
	E.bullet		= *bullet			;
	
	switch(Type)
	{
	case EVENT_HIT:
		{
			E.dynamic		= _dynamic			;
			E.result		= ObjectHit			(bullet,end_point,R,tgt_material,E.normal);			
			E.point			= end_point			;
			E.R				= R					;
			E.tgt_material	= tgt_material		;
			if (_dynamic)	
			{
				//	E.Repeated = (R.O->ID() == E.bullet.targetID);
				//	bullet->targetID = R.O->ID();

				E.Repeated = (R.O->ID() == E.bullet.targetID);
				if (GameID() == GAME_SINGLE)
				{
					bullet->targetID = R.O->ID();
				}
				else
				{
					if (bullet->targetID != R.O->ID())
					{
						CGameObject* pGO = smart_cast<CGameObject*>(R.O);
						if (!pGO || !pGO->BonePassBullet(R.element))
							bullet->targetID = R.O->ID();						
					}
				}
			};
		}break;
	case EVENT_REMOVE:
		{
			E.tgt_material	= tgt_material		;
		}break;
	}	
}