Download

Attaching AAIController to specific pawn

I am creating an AI drone simulator to test out path planning algorithms using c++. How can I spawn a single pawn, preferably the player, and control this pawn through a path planning algorithm. The drone will search for a target and once the target is in a line of sight, it will find the most efficient path to land on the target.

If u spawn a single pawn which is the player, u should not be using AIController but PlayerController.
Look at the TopDown template project to see how navigation/path finding can be used together with a player pawn that has a target destination and move to the destination.

For custom path finding u probably wont be using the navmesh and UE4 path finding, but it should give u an idea of how to get started.
I have a project with custom path finding (path finding done by external server)

In my pawn Tick method i move toward the destination point.



	FVector TargetDirection = TargetLocation - GetActorLocation();
	const float TargetDistance = TargetDirection.Size2D();
	if (TargetDistance > 50.0f)
	{
		// Get the facing direction
		FVector FacingDirection = FVector(TargetDirection.X, TargetDirection.Y, 0.0f);
		FacingDirection.Normalize();

		// We only care about rotation around the YAW axis
		FRotator TargetRotation = FRotator(0.0f, FacingDirection.Rotation().Yaw, 0.0f);

		// We set the characters facing to match the facing of the vector
		SetActorRotation(TargetRotation);

		// Move the actor
		AddMovementInput(TargetDirection);
	}