void AGameplayAbilityTargetActor_Trace::AimWithPlayerController(const AActor* InSourceActor, FCollisionQueryParams Params, const FVector& TraceStart, FVector& OutTraceEnd, bool bIgnorePitch) const
{
	if (!OwningAbility) // Server and launching client only
	{
		return;
	}

	APlayerController* PC = OwningAbility->GetCurrentActorInfo()->PlayerController.Get();
	check(PC);

	FVector ViewStart;
	FRotator ViewRot;
	PC->GetPlayerViewPoint(ViewStart, ViewRot);

	const FVector ViewDir = ViewRot.Vector();
	FVector ViewEnd = ViewStart + (ViewDir * MaxRange);

	ClipCameraRayToAbilityRange(ViewStart, ViewDir, TraceStart, MaxRange, ViewEnd);

	FHitResult HitResult;
	LineTraceWithFilter(HitResult, InSourceActor->GetWorld(), Filter, ViewStart, ViewEnd, TraceProfile.Name, Params);

	const bool bUseTraceResult = HitResult.bBlockingHit && (FVector::DistSquared(TraceStart, HitResult.Location) <= (MaxRange * MaxRange));

	const FVector AdjustedEnd = (bUseTraceResult) ? HitResult.Location : ViewEnd;

	FVector AdjustedAimDir = (AdjustedEnd - TraceStart).GetSafeNormal();
	if (AdjustedAimDir.IsZero())
	{
		AdjustedAimDir = ViewDir;
	}

	if (!bTraceAffectsAimPitch && bUseTraceResult)
	{
		FVector OriginalAimDir = (ViewEnd - TraceStart).GetSafeNormal();

		if (!OriginalAimDir.IsZero())
		{
			// Convert to angles and use original pitch
			const FRotator OriginalAimRot = OriginalAimDir.Rotation();

			FRotator AdjustedAimRot = AdjustedAimDir.Rotation();
			AdjustedAimRot.Pitch = OriginalAimRot.Pitch;

			AdjustedAimDir = AdjustedAimRot.Vector();
		}
	}

	OutTraceEnd = TraceStart + (AdjustedAimDir * MaxRange);
}
AActor* USCarryObjectComponent::GetActorInView()
{
	APawn* PawnOwner = Cast<APawn>(GetOwner());
	AController* Controller = PawnOwner->Controller;
	if (Controller == nullptr)
	{
		return nullptr;
	}

	FVector CamLoc;
	FRotator CamRot;
	Controller->GetPlayerViewPoint(CamLoc, CamRot);

	const FVector TraceStart = CamLoc;
	const FVector Direction = CamRot.Vector();
	const FVector TraceEnd = TraceStart + (Direction * MaxPickupDistance);

	FCollisionQueryParams TraceParams(TEXT("TraceActor"), true, PawnOwner);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = false;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingle(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);

	//DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);

	return Hit.GetActor();
}
void ASoftDesignTrainingPlayerController::OnTakeCoverPressed()
{
    APawn* const Pawn = GetPawn();

    if (Pawn)
    {
        FVector actorLocation = Pawn->GetActorLocation();
        FRotator actorRotation = Pawn->GetActorRotation();
        FVector coverTestStart = actorLocation;
        FVector coverTestEnd = actorLocation + 400.0f * actorRotation.Vector();

        UWorld* currentWorld = GetWorld();

        static FName InitialCoverSweepTestName = TEXT("InitialCoverSweepTest");
        FHitResult hitResult;
        FQuat shapeRot = FQuat::Identity;
        FCollisionShape collShape = FCollisionShape::MakeSphere(Pawn->GetSimpleCollisionRadius());
        FCollisionQueryParams collQueryParams(InitialCoverSweepTestName, false, Pawn);
        currentWorld->DebugDrawTraceTag = InitialCoverSweepTestName;
        FCollisionObjectQueryParams collObjQueryParams(ECC_WorldStatic);
        
        UDesignTrainingMovementComponent* charMovement = Cast<UDesignTrainingMovementComponent>(Pawn->GetMovementComponent());

        if (currentWorld->SweepSingleByObjectType(hitResult, coverTestStart, coverTestEnd, shapeRot, collObjQueryParams, collShape, collQueryParams))
        {
            if (charMovement->ValidateCover(hitResult))
            {
                MoveToCoverDestination(hitResult.Location);
            }
        }
    }
}
bool AKinectPlayerController::FindDeathCameraSpot(FVector& CameraLocation, FRotator& CameraRotation)
{

	const FVector PawnLocation = GetPawn()->GetActorLocation();
	FRotator ViewDir = GetControlRotation();
	ViewDir.Pitch = -45.0f;

	const float YawOffsets[] = { 0.0f, -180.0f, 90.0f, -90.0f, 45.0f, -45.0f, 135.0f, -135.0f };
	const float CameraOffset = 600.0f;
	FCollisionQueryParams TraceParams(TEXT("DeathCamera"), true, GetPawn());

	for (int32 i = 0; i < ARRAY_COUNT(YawOffsets); i++)
	{
		FRotator CameraDir = ViewDir;
		CameraDir.Yaw += YawOffsets[i];
		CameraDir.Normalize();

		const FVector TestLocation = PawnLocation - CameraDir.Vector() * CameraOffset;
		const bool bBlocked = GetWorld()->LineTraceTest(PawnLocation, TestLocation, ECC_Camera, TraceParams);

		if (!bBlocked)
		{
			CameraLocation = TestLocation;
			CameraRotation = CameraDir;
			return true;
		}
	}

	return false;
}
AInventoryItem* APlayerCharacter::GetUsableItemInView()
{
	FVector camLoc;
	FRotator camRot;

	if (Controller == NULL)
		return NULL;

	Controller->GetPlayerViewPoint(camLoc, camRot);
	const FVector start_trace = camLoc;
	const FVector direction = camRot.Vector();
	const FVector end_trace = start_trace + (direction * MaxUseDist);

	FCollisionQueryParams TraceParams(FName(TEXT("")), true, this);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = true;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingleByChannel(Hit, start_trace, end_trace, ECollisionChannel::ECC_EngineTraceChannel1, TraceParams);

	//DrawDebugLine(GetWorld(), start_trace, end_trace, FColor(255, 0, 0), false, -1, 0, 12.333);

	return Cast<AInventoryItem>(Hit.GetActor());
}
/**
*	Get location and rotation of camera. Sets players view point to camera location and rotation.
*	Sets where the trace will start, which direction, and where it ends. Traceparms setup to return details of whats collided.
*	Traces a ray against the world, returning the first blocking hit.
*
*	@params location to store hit info, distance of trace ray, the collision channel 
*	@return return the hit actor.
**/
bool APlayerCharacter::TraceFromSelf(FHitResult& OutResult, const float TraceDistance, ECollisionChannel const CollisionChannel)
{
	if (Controller)
	{
		FVector CameraLoc; 
		FRotator CameraRot;
		Controller->GetPlayerViewPoint(CameraLoc, CameraRot); //Location to cast ray (from player)

		FVector const BeginTrace = CameraLoc;
		FVector const ShootDir = CameraRot.Vector();
		FVector const TraceEnd = BeginTrace + ShootDir * TraceDistance;

		FCollisionQueryParams TraceParms(FName(TEXT("TraceFromSelf")), true, this); //returns what collided

		bool bHitReturned = false; //to determine if anything hit
		UWorld* const World = GetWorld(); 
		if (World)
		{
			bHitReturned = World->LineTraceSingleByChannel(OutResult, BeginTrace, TraceEnd, CollisionChannel, TraceParms); 
		}

		TraceParms.bTraceAsyncScene = true; //Whether we should perform the trace in the asynchronous scene.Default is false.
		TraceParms.bReturnPhysicalMaterial = false;  //Only fill in the PhysMaterial field 
		TraceParms.bTraceComplex = true; //Whether we should trace against complex collision

		return bHitReturned;
	}
	return false; //if there is no controller, nothing traced.
} 
AUsableActor* AXtremeJanitorCharacter::GetUsableInView()
{
	FVector CamLoc;
	FRotator CamRot;

	if (Controller == NULL)
		return NULL;

	Controller->GetPlayerViewPoint(CamLoc, CamRot);
	const FVector TraceStart = CamLoc;
	const FVector Direction = CamRot.Vector();
	const FVector TraceEnd = TraceStart + (Direction * MaxUseDistance);

	FCollisionQueryParams TraceParams(FName(TEXT("TraceUsableActor")), true, this);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = true;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);

	// Cette ligne sera en commentaire plus tard
	DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);

	return Cast<AUsableActor>(Hit.GetActor());
}
Esempio n. 8
0
const FHitResult UGrabber::GetFirstPhysicsBodyInReach()
{
	/// Get Player position and view data
	FVector PlayerViewPointLocation;
	FRotator PlayerViewPointRotation;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerViewPointLocation, OUT PlayerViewPointRotation);

	/*UE_LOG(LogTemp, Warning, TEXT("Location: %s, Rotation: %s"), *PlayerViewPointLocation.ToString(), *PlayerViewPointRotation.ToString());*/

	/// Draw Debug Line based on how far can reach
	FVector LineTraceEnd = PlayerViewPointLocation + (PlayerViewPointRotation.Vector() * Reach);
	//DrawDebugLine(GetWorld(), PlayerViewPointLocation, LineTraceEnd, FColor(255, 0, 0), false, 0.f, 0.f, 10.f);

	/// Decide what can detect as collision
	FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());

	FHitResult LineTraceHit;
	GetWorld()->LineTraceSingleByObjectType(OUT LineTraceHit, PlayerViewPointLocation, LineTraceEnd, FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody), TraceParameters);

	AActor* ActorHit = LineTraceHit.GetActor();
	if (ActorHit) {
		UE_LOG(LogTemp, Warning, TEXT("Line Trace Hit: %s"), *(ActorHit->GetName()));
	}
	return LineTraceHit;
}
void AITP380_RocketThingPawn::FireCluster(){
	UWorld* const World = GetWorld();
	for (int k = 0; k < NumFiredAtOnce; k++){
		FRotator FireRotation = curFireDirection.Rotation();
		FRotator randRotation = FRotator(FireRotation.Pitch, FireRotation.Yaw + FMath::RandRange(-90, 90), FireRotation.Roll);
		// Spawn projectile at an offset from this pawn
		const FVector SpawnLocation = GetActorLocation() + randRotation.RotateVector(GunOffset);

		if (World != NULL)
		{
			// spawn the projectile
			ARocketProjectile* projectile = World->SpawnActor<ARocketProjectile>(SpawnLocation, randRotation);
			projectile->targetDirection = FireRotation.Vector();
		}

		//bCanFire = false;

		// try and play the sound if specified
		
	}
	World->GetTimerManager().SetTimer(TimerHandle_ShotTimerExpired, this, &AITP380_RocketThingPawn::ShotTimerExpired, FireRate);
	projectilesFired += NumFiredAtOnce;
	
	if (projectilesFired < NumFiredTotal)
		World->GetTimerManager().SetTimer(TimerHandle_ShotIntervalExpired, this, &AITP380_RocketThingPawn::FireCluster, pauseBetweenFires);
	else
		projectilesFired = 0;
}
Esempio n. 10
0
/*Description: Raycasts forward and detects where the player is aiming to adjust the reticles*/
bool APoseidonCharacter::TraceHitForward(APlayerController* InController, FHitResult& OutTraceResult)
{
	// Calculate the direction we are 'looking'  
	FVector CamLoc;
	FRotator CamRot;
	InController->GetPlayerViewPoint(CamLoc, CamRot);
	const FVector TraceDirection = CamRot.Vector();

	// Calculate the start location for trace  
	FVector StartTrace = FVector::ZeroVector;
	if (InController)
	{
		FRotator UnusedRotation;
		InController->GetPlayerViewPoint(StartTrace, UnusedRotation);

		// Adjust trace so there is nothing blocking the ray between the camera and the pawn, and calculate distance from adjusted start  
		StartTrace = StartTrace + TraceDirection * ((GetActorLocation() - StartTrace) | TraceDirection);
	}

	// Calculate endpoint of trace  
	const FVector EndTrace = StartTrace + TraceDirection * mGrappleRange;

	// Setup the trace query  
	static FName FireTraceIdent = FName(TEXT("GrappleTrace"));
	FCollisionQueryParams TraceParams(FireTraceIdent, true, this);
	TraceParams.bTraceAsyncScene = true;

	// Perform the trace  
	GetWorld()->LineTraceSingleByChannel(OutTraceResult, StartTrace, EndTrace, COLLISION_GRAPPLE, TraceParams);

	if (OutTraceResult.GetActor() != NULL)
	{
		FString filterEnemy = TEXT("Character");

		if (OutTraceResult.GetActor()->GetHumanReadableName().Contains(filterEnemy))
		{
			if (mIsGrappleReady)
			{
				PlayerHUD->ChangeCrosshair(EReticleEnum::RE_HIT_AIM);
			}
		}
		else
		{
			if (mIsGrappleReady)
			{
				PlayerHUD->ChangeCrosshair(EReticleEnum::RE_AIM);
			}
			else
			{
				PlayerHUD->ChangeCrosshair(EReticleEnum::RE_HIP);
			}
		}

		return true;
	}

	PlayerHUD->ChangeCrosshair(EReticleEnum::RE_HIP);

	return false;
}
Esempio n. 11
0
void AShotgun::ProjectileFire()
{
	Super::ProjectileFire();

	if (BulletClass != NULL)
	{
		FActorSpawnParameters SpawnParams;
		SpawnParams.Owner = this;
		SpawnParams.Instigator = Instigator;
		FVector BulletLoc = WeaponMesh->GetSocketLocation("BulletOrigin");
		FRotator BulletRot = WeaponMesh->GetSocketRotation("BulletOrigin");

		const int32 RandomSeed = FMath::Rand();
		FRandomStream WeaponRandomStream(RandomSeed);
		const float SpreadCone = FMath::DegreesToRadians(WeaponConfig.WeaponSpread * 0.5);
		FVector ShootDir = WeaponRandomStream.VRandCone(BulletRot.Vector(), SpreadCone, SpreadCone);
		ShootDir.Z = 0;

		ABullet* const Bullet = GetWorld()->SpawnActor<ABullet>(BulletClass, BulletLoc, BulletRot, SpawnParams);
		if (Bullet)
		{
			Bullet->InitVelocity(ShootDir);
			Bullet->SetDamage(5.0f);
		}
	}

	bCanShoot = false;
	UWorld* const World = GetWorld();
	if (World != NULL)
	{
		World->GetTimerManager().SetTimer(TimeHandle_ShootCooldownExpired, this, &AMyPawnWeapon::ShootCooldownExpired, WeaponConfig.TimeBetweenShots);
	}
}
Esempio n. 12
0
void UCheatManager::DamageTarget(float DamageAmount)
{
	APlayerController* const MyPC = GetOuterAPlayerController();
	if ((MyPC == NULL) || (MyPC->PlayerCameraManager == NULL))
	{
		return;
	}

	check(GetWorld() != NULL);
	FVector const CamLoc = MyPC->PlayerCameraManager->GetCameraLocation();
	FRotator const CamRot = MyPC->PlayerCameraManager->GetCameraRotation();

	FCollisionQueryParams TraceParams(NAME_None, true, MyPC->GetPawn());
	FHitResult Hit;
	bool bHit = GetWorld()->LineTraceSingle(Hit, CamLoc, CamRot.Vector() * 100000.f + CamLoc, ECC_Pawn, TraceParams);
	if (bHit)
	{
		check(Hit.GetActor() != NULL);
		FVector ActorForward, ActorSide, ActorUp;
		FRotationMatrix(Hit.GetActor()->GetActorRotation()).GetScaledAxes(ActorForward, ActorSide, ActorUp);

		FPointDamageEvent DamageEvent(DamageAmount, Hit, -ActorForward, UDamageType::StaticClass());
		Hit.GetActor()->TakeDamage(DamageAmount, DamageEvent, MyPC, MyPC->GetPawn());
	}
}
Esempio n. 13
0
void APawnWithCamera::DoTrace()
{
	FVector Loc = CameraOne->GetActorLocation();
	UE_LOG(LogClass, Error, TEXT("Loc is %s"), *Loc.ToString());
	FRotator Rot = CameraOne->GetActorRotation();
	UE_LOG(LogClass, Error, TEXT("Rot is %s"), *Rot.ToString());
	FVector Start = Loc;
	UE_LOG(LogClass, Error, TEXT("Start is %s"), *Start.ToString());
	FVector End = Loc + (Rot.Vector() * Distance);
	UE_LOG(LogClass, Error, TEXT("End is %s"), *End.ToString());
	TempActor->SetActorLocation(End);

	FCollisionQueryParams TraceParam = FCollisionQueryParams(FName(TEXT("Trace")), true, this);
	TraceParam.bTraceComplex = true;
	TraceParam.bTraceAsyncScene = true;
	TraceParam.bReturnPhysicalMaterial = false;
	TraceParam.AddIgnoredActor(this);

	FHitResult Hit(ForceInit);

	GetWorld()->LineTraceSingle(Hit, Start, End, ECC_Pawn, TraceParam);
	DrawDebugLine(GetWorld(), Start, End, FColor(255, 0, 0), false, -1, 0, 12.33f);

	if (Hit.bBlockingHit)
	{
		UE_LOG(LogClass, Error, TEXT("Hit Something"));
	}
	else
	{
		UE_LOG(LogClass, Error, TEXT("No Hit"));
	}
}
/*
Performs ray-trace to find closest looked-at UsableActor.
*/
ASUsableActor* ASCharacter::GetUsableInView()
{
	FVector CamLoc;
	FRotator CamRot;

	if (Controller == nullptr)
		return nullptr;

	Controller->GetPlayerViewPoint(CamLoc, CamRot);
	const FVector TraceStart = CamLoc;
	const FVector Direction = CamRot.Vector();
	const FVector TraceEnd = TraceStart + (Direction * MaxUseDistance);

	FCollisionQueryParams TraceParams(TEXT("TraceUsableActor"), true, this);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;

	/* Not tracing complex uses the rough collision instead making tiny objects easier to select. */
	TraceParams.bTraceComplex = false;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);

	//DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);

	return Cast<ASUsableActor>(Hit.GetActor());
}
Esempio n. 15
0
void UCheatManager::DestroyTarget()
{
	APlayerController* const MyPC = GetOuterAPlayerController();
	if ((MyPC == NULL) || (MyPC->PlayerCameraManager == NULL))
	{
		return;
	}

	check(GetWorld() != NULL);
	FVector const CamLoc = MyPC->PlayerCameraManager->GetCameraLocation();
	FRotator const CamRot = MyPC->PlayerCameraManager->GetCameraRotation();

	FCollisionQueryParams TraceParams(NAME_None, true, MyPC->GetPawn());
	FHitResult Hit;
	bool bHit = GetWorld()->LineTraceSingle(Hit, CamLoc, CamRot.Vector() * 100000.f + CamLoc, ECC_Pawn, TraceParams);
	if (bHit)
	{
		check(Hit.GetActor() != NULL);
		APawn* Pawn = Cast<APawn>(Hit.GetActor());
		if (Pawn != NULL)
		{
			if ((Pawn->Controller != NULL) && (Cast<APlayerController>(Pawn->Controller) == NULL))
			{
				// Destroy any associated controller as long as it's not a player controller.
				Pawn->Controller->Destroy();
			}
		}

		Hit.GetActor()->Destroy();
	}
}
Esempio n. 16
0
void APistol::ProjectileFire()
{
	Super::ProjectileFire();

	if (BulletClass != NULL)
	{
		FActorSpawnParameters SpawnParams;
		SpawnParams.Owner = this;
		SpawnParams.Instigator = Instigator;
		FVector BulletLoc = WeaponMesh->GetSocketLocation("BulletOrigin");
		FRotator BulletRot = WeaponMesh->GetSocketRotation("BulletOrigin");

		APlayerBullet* const Bullet = GetWorld()->SpawnActor<APlayerBullet>(BulletClass, BulletLoc, BulletRot, SpawnParams);
		if (Bullet)
		{
			Bullet->InitVelocity(BulletRot.Vector());
			Bullet->SetDamage(10.0f);
		}
	}

	bCanShoot = false;
	UWorld* const World = GetWorld();
	if (World != NULL)
	{
		World->GetTimerManager().SetTimer(TimeHandle_ShootCooldownExpired, this, &AMyPawnWeapon::ShootCooldownExpired, WeaponConfig.TimeBetweenShots);
	}
}
Esempio n. 17
0
void ABlinkAbility::StartAbility()
{

	float ManaCost = 20;
	float CoolDown = 5;
	float curMana = owner->getMana();

	if (curMana - ManaCost >= 0 && !(owner->getbCDBlink()))
	{
		owner->setMana(curMana - ManaCost);
		//owner->BlinkInCD();
		bCoolDown = true;

		GetWorld()->GetTimerManager().SetTimer(CDHandle_Ability, this, &ABlinkAbility::callCoolDown, CoolDown);
		if (AbilitySound && AbilityFX)
		{
			UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), AbilityFX, GetActorLocation());
			UGameplayStatics::PlaySoundAttached(AbilitySound, owner->ShipMeshComponent);
		}

		FRotator curFacing = GetActorRotation();
		FVector curLoc = GetActorLocation();

		//get facing 
		FVector destLoc = curLoc + curFacing.Vector() * 700;
		owner->TeleportTo(destLoc, curFacing);
		UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), AbilityFX, GetActorLocation());
	}
}
AActor* USCarryObjectComponent::GetActorInView()
{
	APawn* PawnOwner = Cast<APawn>(GetOwner());
	AController* Controller = PawnOwner->Controller;
	if (Controller == nullptr)
	{
		return nullptr;
	}

	FVector CamLoc;
	FRotator CamRot;
	Controller->GetPlayerViewPoint(CamLoc, CamRot);

	const FVector TraceStart = CamLoc;
	const FVector Direction = CamRot.Vector();
	const FVector TraceEnd = TraceStart + (Direction * MaxPickupDistance);

	FCollisionQueryParams TraceParams(TEXT("TraceActor"), true, PawnOwner);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = false;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);

	/* Check to see if we hit a staticmesh component that has physics simulation enabled */
	UStaticMeshComponent* MeshComp = Cast<UStaticMeshComponent>(Hit.GetComponent());
	if (MeshComp && MeshComp->IsSimulatingPhysics())
	{
		return Hit.GetActor();
	}

	return nullptr;
}
Esempio n. 19
0
void ABaseCharacter::OnFire()
{
	
	if (ProjectileClass != NULL)
	{
		//Gets the direction that the camera is looking
		FVector cameraLoc;
		FRotator cameraRot;
		GetActorEyesViewPoint(cameraLoc, cameraRot);
		FVector const muzzleLocation = cameraLoc + FTransform(cameraRot).TransformVector(MuzzleOffset);
		FRotator muzzleRotation = cameraRot;
		//Skew the aim point upward
		muzzleRotation.Pitch += 10.0f;
		UWorld* const world = GetWorld();
		if (world)
		{
			FActorSpawnParameters spawnParameters;
			spawnParameters.Owner = this;
			spawnParameters.Instigator = Instigator;
			
			//Spawns the projectile
			ABaseProjectile* const projectile = world->SpawnActor<ABaseProjectile>(ProjectileClass, muzzleLocation, muzzleRotation, spawnParameters);
			if (projectile)
			{
				//Gets launch direction
				FVector const launchDir = muzzleRotation.Vector();
				projectile->InitVelocity(launchDir);
			}
		}
	}
}
Esempio n. 20
0
void UMWBotSensorComponent::UpdateRotation(float DeltaSeconds)
{
	// desRot is DesiredRotation with optionally added random angle
	const FRotator curRot = GetRelativeTransform().Rotator();
	FRotator desRot = bEnableSensorWander ? ApplyRandomAngle(DesiredRotation) : DesiredRotation;

	// clamp the aiming angle (desired rotation)

	const FVector defAim = DefaultRotation.Vector();
	const FVector desAim = desRot.Vector();

	const float maxAngRad = PI * ViewingAngle / 180.f;
	const float curCos = defAim | desAim;
	const float minCos = FMath::Cos(maxAngRad);
	if (curCos < minCos) // out of range
	{
		// Find quaternion which rotates the eye in the aimDef-aimDir plane
		const FVector axis = defAim ^ desAim;
		const FQuat quat(axis, maxAngRad);

		desRot = quat.RotateVector(defAim).Rotation();
	}

	// smoothly change the sensor aiming
	const float interpSpeed = bCrazy ? CrazyReaction : bAlarm ? AlarmReaction : Reaction;
	FRotator newRot = FMath::RInterpTo(curRot, desRot, DeltaSeconds, interpSpeed);
	SetRelativeRotation(newRot);
}
FVector AShooterWeapon::GetAdjustedAim() const
{
	AShooterPlayerController* const PlayerController = Instigator ? Cast<AShooterPlayerController>(Instigator->Controller) : NULL;
	FVector FinalAim = FVector::ZeroVector;
	// If we have a player controller use it for the aim
	if (PlayerController)
	{
		FVector CamLoc;
		FRotator CamRot;
		PlayerController->GetPlayerViewPoint(CamLoc, CamRot);
		FinalAim = CamRot.Vector();
	}
	else if (Instigator)
	{
		// Now see if we have an AI controller - we will want to get the aim from there if we do
		AShooterAIController* AIController = MyPawn ? Cast<AShooterAIController>(MyPawn->Controller) : NULL;
		if(AIController != NULL )
		{
			FinalAim = AIController->GetControlRotation().Vector();
		}
		else
		{			
			FinalAim = Instigator->GetBaseAimRotation().Vector();
		}
	}

	return FinalAim;
}
void USCarryObjectComponent::Throw()
{
	if (!GetIsCarryingActor())
		return;

	if (GetOwner()->Role < ROLE_Authority)
	{
		ServerThrow();
		return;
	}

	/* Grab a reference to the MeshComp before dropping the object */
	UStaticMeshComponent* MeshComp = GetCarriedMeshComp();
	if (MeshComp)
	{
		/* Detach and re-enable collision */
		OnDropMulticast();

		APawn* OwningPawn = Cast<APawn>(GetOwner());
		if (OwningPawn)
		{
			/* Re-map uint8 to 360 degrees */
			const float PawnViewPitch = (OwningPawn->RemoteViewPitch / 255.f)*360.f;

			FRotator NewRotation = GetComponentRotation();
			NewRotation.Pitch = PawnViewPitch;

			/* Apply physics impulse, ignores mass */
			MeshComp->AddImpulse(NewRotation.Vector() * 1000, NAME_None, true);
		}
	}
}
Esempio n. 23
0
void AConstructorWeapon::Fire()
{
	Super::Fire();

	if (TheLevelBlockConstructor == NULL)
	{
		if (GetWorld() && GetWorld()->GetAuthGameMode() && GetWorld()->GetAuthGameMode<ARadeGameMode>())
		{
			TheLevelBlockConstructor = GetWorld()->GetAuthGameMode<ARadeGameMode>()->TheLevelBlockConstructor;
		}
	}

	if (TheLevelBlockConstructor)
	{

		FVector CamLoc;
		FRotator CamRot;
		ThePlayer->Controller->GetPlayerViewPoint(CamLoc, CamRot); // Get the camera position and rotation
		FVector StartTrace = Mesh1P->GetSocketLocation(TEXT("FireSocket"));
		//	CamLoc; // trace start is the camera location
		FVector Direction = CamRot.Vector();
		FVector EndTrace = StartTrace + Direction *MainFire.FireDistance;

		if (TheLevelBlockConstructor->AddNewBlock(BlockArchetype, EndTrace, this)) UseMainFireAmmo();
	}
}
Esempio n. 24
0
void AAirCurrent::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);
	Duration += DeltaSeconds;
	if (HasAuthority())
	{
		TArray<AActor* > OverlappedActors;
		CollisionComp->GetOverlappingActors(OverlappedActors);
		for (int32 i = 0; i < OverlappedActors.Num(); i++)
		{
			ATotemCharacter* TotemCharacter = Cast<ATotemCharacter>(OverlappedActors[i]);
			if (TotemCharacter && !TotemCharacter->IsPendingKill() && !TotemCharacter->Invincible())
			{
				FRotator rot = GetActorRotation();
				FVector LaunchDir = rot.Vector();
				LaunchDir.Normalize(0.01f);
				LaunchDir *= LaunchSpeed;

				//EMovementMode mode = TotemCharacter->CharacterMovement->MovementMode;
				//TotemCharacter->LaunchCharacter(LaunchDir, true, true);
				//TotemCharacter->GetCharacterMovement()->Velocity += LaunchDir;
				TotemCharacter->LaunchCharacter(LaunchDir, false, false);
				//TotemCharacter->CharacterMovement->AddForce(LaunchDir);
				//TotemCharacter->CharacterMovement->SetMovementMode(mode);
			}
			
			//add a lot of type check, hope fix the crash
			UActorComponent* actorComp = OverlappedActors[i]->GetComponentByClass(UProjectileMovementComponent::StaticClass());
			if (actorComp !=nullptr)
			{
				UProjectileMovementComponent* movementComp = Cast<UProjectileMovementComponent>(actorComp);
				if (movementComp && !movementComp->IsPendingKill())
				{
					FRotator rot = GetActorRotation();
					FVector LaunchDir = rot.Vector();
					LaunchDir.Normalize(0.01f);
					if (movementComp)
					{
						LaunchDir *= movementComp->GetMaxSpeed();
						movementComp->Velocity = LaunchDir;
					}
				}
			}
			
		}
	}	
}
Esempio n. 25
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);
		}
	}
}
Esempio n. 26
0
void UAkGameplayStatics::PostEventAtLocationByName( const FString& EventName, FVector Location, FRotator Orientation, UObject* WorldContextObject )
{
	FAkAudioDevice * AkAudioDevice = FAkAudioDevice::Get();
	UWorld* CurrentWorld = GEngine->GetWorldFromContextObject(WorldContextObject);
	if( CurrentWorld->AllowAudioPlayback() && AkAudioDevice )
	{
		AkAudioDevice->PostEventAtLocation(EventName, Location, Orientation.Vector(), GEngine->GetWorldFromContextObject(WorldContextObject) );
	}
}
Esempio n. 27
0
FVector UGrabber::GetReachLineEnd(){
	FVector PlayerViewPointLocation;
	FRotator PlayerViewPointRotation;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(
		OUT PlayerViewPointLocation,
		OUT PlayerViewPointRotation
	);
	return PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;
}
Esempio n. 28
0
FVector UGrabber::GetReachLineEnd()
{
	// Get player viewpoint
	FVector ViewPointLocation;
	FRotator ViewPointRotation;

	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT ViewPointLocation, OUT ViewPointRotation);

	return ViewPointLocation + ViewPointRotation.Vector()* Reach;
}
Esempio n. 29
0
void UAIPerceptionComponent::GetLocationAndDirection(FVector& Location, FVector& Direction) const
{
    const AActor* OwnerActor = Cast<AActor>(GetOuter());
    if (OwnerActor != nullptr)
    {
        FRotator ViewRotation;
        OwnerActor->GetActorEyesViewPoint(Location, ViewRotation);
        Direction = ViewRotation.Vector();
    }
}
Esempio n. 30
0
FVector UGTTraceBase::GetPCCameraAim()
{
	FVector OutStartTrace = FVector::ZeroVector;
	FRotator AimDir;
	if (TraceInterface->GetGamePlayerController())
	{
		TraceInterface->GetGamePlayerController()->GetPlayerViewPoint(OutStartTrace, AimDir);
	}
	return AimDir.Vector();
}