Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MyAIController.cpp
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "niemamjuzsily.h"
- #include "MyAIController.h"
- #include "Engine.h"
- AMyAIController::AMyAIController(const FObjectInitializer &ObjectInitializer) : Super(ObjectInitializer)
- {
- if (GEngine) GEngine->AddOnScreenDebugMessage(FMath::Rand(), 5.f, FColor::Yellow, FString("Controler constructor"));
- }
- void AMyAIController::Tick(float DeltaTime){
- TempTick += DeltaTime;
- if (LastTick + 1 < TempTick){
- LastTick = TempTick;
- if (GEngine) GEngine->AddOnScreenDebugMessage(FMath::Rand(), 5.f, FColor::Yellow, FString("Controler Tick"));
- //GetPawn()->SetActorLocation(FVector(FMath::RandRange(-300, 300), FMath::RandRange(-300, 300), FMath::RandRange(-300, 300))); // this thing works
- MoveToLocation(FVector(FMath::RandRange(-300, 300), FMath::RandRange(-300, 300), FMath::RandRange(-300, 300)), -1.0f, true, true); // this thing does not work
- }
- }
- ///////////////////////////////////////////////////////////////
- AMyPawn.cpp constructor
- AMyPawn::AMyPawn(const FObjectInitializer &ObjectInitializer) : Super(ObjectInitializer)
- {
- MeszkaPawna = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PawnMesh"));
- static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMesh(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Sphere'"));
- static ConstructorHelpers::FObjectFinder<UMaterial> Material_Blue(TEXT("MaterialInstanceConstant'/Game/StarterContent/Materials/M_Water_Lake.M_Water_Lake'"));
- MovementComp = ObjectInitializer.CreateDefaultSubobject<UMovementComponentDlaPawna>(this, TEXT("MovementComp")); //
- MeszkaPawna->SetCollisionProfileName("BlockAll");
- //MeszkaPawna->SetSimulatePhysics(true);
- MeszkaPawna->SetStaticMesh(StaticMesh.Object);
- MeszkaPawna->SetMaterial(0, Material_Blue.Object);
- RootComponent = MeszkaPawna;
- AIControllerClass = AMyAIController::StaticClass();
- PrimaryActorTick.bCanEverTick = true;
- }
- ///////////////////////////////////////////////////////////////
- And the custom movement component
- .h
- UCLASS()
- class NIEMAMJUZSILY_API UMovementComponentDlaPawna : public UCharacterMovementComponent
- {
- GENERATED_BODY()
- virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
- };
- .cpp
- void UMovementComponentDlaPawna::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
- {
- Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
- if (GEngine) GEngine->AddOnScreenDebugMessage(FMath::Rand(), 5.f, FColor::Yellow, FString("Movement Component Tick")); // this is NOT called
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement