So I’ve followed along and as far as I can see I have everything pretty much the same (aside from the Bug where parts of my Tank disappear and resetting the Physics material and Tank Friction)
Heres my code for the Movement:
#include "TankTrack.h"
#include "Math/Vector.h"
#include "TankMovementComponent.h"
void UTankMovementComponent::Initialise(UTankTrack* LeftTrackToSet, UTankTrack* RightTrackToSet)
{
LeftTrack = LeftTrackToSet;
RightTrack = RightTrackToSet;
}
void UTankMovementComponent::RequestDirectMove(const FVector& MoveVelocity, bool bForceMaxSpeed)
{
// No need to call Super as we're replacing the functionality
auto TankForward = GetOwner()->GetActorForwardVector().GetSafeNormal();
auto AIForwardIntention = MoveVelocity.GetSafeNormal();
auto ForwardThrow = FVector::DotProduct(TankForward, AIForwardIntention);
IntendMoveForward(ForwardThrow);
auto RightThrow = FVector::CrossProduct(TankForward, AIForwardIntention).Z;
IntendTurnRight(RightThrow);
// UE_LOG(LogTemp, Warning, TEXT("%s vectoring to %s"), *TankName, *MoveVelocityString)
}
void UTankMovementComponent::IntendMoveForward(float Throw)
{
if (!LeftTrack || !RightTrack) { return; }
LeftTrack->SetThrottle(Throw);
RightTrack->SetThrottle(Throw);
// TODO prevent double-speed due to dual control use
}
void UTankMovementComponent::IntendTurnRight(float Throw)
{
if (!LeftTrack || !RightTrack) { return; }
LeftTrack->SetThrottle(Throw);
RightTrack->SetThrottle(-Throw);
// TODO prevent double-speed due to dual control use
}
and the Header file:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/NavMovementComponent.h"
#include "TankTrack.h"
#include "TankMovementComponent.generated.h"
class UTankTrack;
/**
*
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class BATTLE_TANK_API UTankMovementComponent : public UNavMovementComponent
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = Input)
void IntendMoveForward(float Throw);
UFUNCTION(BlueprintCallable, Category = Setup)
void Initialise(UTankTrack* LeftTrackToSet, UTankTrack* RightTrackToSet);
UFUNCTION(BlueprintCallable, Category = Input)
void IntendTurnRight(float Throw);
virtual void RequestDirectMove(const FVector& MoveVolocity, bool bForceMaxSpeed) override;
private:
UTankTrack* LeftTrack = nullptr;
UTankTrack* RightTrack = nullptr;
};
After looking through stuff for several days, I cannot see where I’m going wrong here