[Community Project] WIP Weather & Water Shader

Hi! is really amazing work I would like to echo along with else.

I’m trying to make a simple AI based boat game to practice with UE4 but I’m having a hard time implementing the AI. In a similar Tank game that is based on land my AI works fine. I’m feel like almost there too but there’s one odd behavior I can’t figure out. Although my behavior tree shows that the AI is able to find the patrol points and sense me as an enemy, it’s not moving towards the patrol points rather just failing the move to call and cycling through the patrol points rapidly as each time it fails the move portion. My instinct tells me that it thinks it can’t reach the patrol points but I’ve been at for 9 hours now and only making it worse. I can’t figure it out :frowning:

Has anyone experienced something similar and can give me some pointers regarding how they got their AI to work the the plugin? I’m not really sure what from my code, or what screenshots specifically to post so let me know if my question is lacking in detail.

BoatAIController.h

BoatMovementComponent.h:


UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class SPACEPIRATES_API UBoatMovementComponent : public UNavMovementComponent
{
	GENERATED_BODY()
	
public:

	UFUNCTION(BlueprintCallable, Category = "Setup")
	void Initialize(UBoatThruster* LeftThrusterToSet, UBoatThruster* RightThrusterToSet);

	UFUNCTION(BlueprintCallable, Category = "Input")
	void IntendMoveForward(float Throw);

	UFUNCTION(BlueprintCallable, Category = "Input")
	void IntendTurnRight(float Throw);


private:
	// TODO check best protection of method
	/** path following: request new velocity
	Called from the pathfinding logic by the AI controller */
	virtual void RequestDirectMove(const FVector& MoveVelocity, bool bForceMaxSpeed);

	UBoatThruster* ForwardThruster = nullptr;
	UBoatThruster* LeftThruster = nullptr;
	UBoatThruster* RightThruster = nullptr;

};


BoatMovementComponent.cpp: Please excuse the super long comments, it was for my own understanding of the subject matter.


/** path following: request new velocity */
void UBoatMovementComponent::RequestDirectMove(const FVector& MoveVelocity, bool bForceMaxSpeed)
{
	/* Get the current forward direction */
	auto BoatForward = GetOwner()->GetActorForwardVector().GetSafeNormal();

	/* Get the intended move direction we want the tank to go in next. */
	auto AIForwardIntention = MoveVelocity.GetSafeNormal();

	/* Set the forward movement to the  product of the tanks current vector
	and the intended vector. */
	auto ForwardThrow = FVector::DotProduct(BoatForward, AIForwardIntention);
	IntendMoveForward(ForwardThrow);


	auto RightThrow = FVector::CrossProduct(BoatForward, AIForwardIntention).Z;
	IntendTurnRight(RightThrow);

	UE_LOG(LogTemp, Warning, TEXT("ForwardThrow: %f RightThrow: %f"), ForwardThrow, RightThrow);
}

/* Initialization is done in blueprint where track assets are assigned to tracks being initialized. */
void UBoatMovementComponent::Initialize(UBoatThruster* LeftThrusterToSet, UBoatThruster* RightThrusterToSet)
{
	LeftThruster = LeftThrusterToSet;
	RightThruster = RightThrusterToSet;

}

void UBoatMovementComponent::IntendMoveForward(float Throw)
{
	/*Ensure that we have a left and right track assigned in BP and initialized. */
	if (!ensure(LeftThruster && RightThruster)) { return; }
	/* Throttle is clamped to -1, 1 so players can't overdrive. */
	LeftThruster->SetThrottle(Throw);
	RightThruster->SetThrottle(Throw);
}

void UBoatMovementComponent::IntendTurnRight(float Throw)
{
	/*Ensure that we have a left and right track assigned in BP and initialized. */
	if (!ensure(LeftThruster && RightThruster)) { return; }
	/* Throttle is clamped to -1, 1 so players can't overdrive. */
	LeftThruster->SetThrottle(-Throw);
	RightThruster->SetThrottle(Throw);
}


I don’t want to post too much code for brevity, if anyone has any ideas please help.