Advertisement
Guest User

Untitled

a guest
May 10th, 2015
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1. MyAIController.cpp
  2.  
  3. // Fill out your copyright notice in the Description page of Project Settings.
  4.  
  5. #include "niemamjuzsily.h"
  6. #include "MyAIController.h"
  7. #include "Engine.h"
  8.  
  9.  
  10. AMyAIController::AMyAIController(const FObjectInitializer &ObjectInitializer) : Super(ObjectInitializer)
  11. {
  12.     if (GEngine) GEngine->AddOnScreenDebugMessage(FMath::Rand(), 5.f, FColor::Yellow, FString("Controler constructor"));
  13. }
  14.  
  15. void AMyAIController::Tick(float DeltaTime){
  16.     TempTick += DeltaTime;
  17.     if (LastTick + 1 < TempTick){
  18.         LastTick = TempTick;
  19.         if (GEngine) GEngine->AddOnScreenDebugMessage(FMath::Rand(), 5.f, FColor::Yellow, FString("Controler Tick"));
  20.         //GetPawn()->SetActorLocation(FVector(FMath::RandRange(-300, 300), FMath::RandRange(-300, 300), FMath::RandRange(-300, 300))); // this thing works
  21.         MoveToLocation(FVector(FMath::RandRange(-300, 300), FMath::RandRange(-300, 300), FMath::RandRange(-300, 300)), -1.0f, true, true); // this thing does not work
  22.     }
  23. }
  24.  
  25. ///////////////////////////////////////////////////////////////
  26.  
  27. AMyPawn.cpp constructor
  28.  
  29. AMyPawn::AMyPawn(const FObjectInitializer &ObjectInitializer) : Super(ObjectInitializer)
  30. {
  31.     MeszkaPawna = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PawnMesh"));
  32.  
  33.     static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMesh(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Sphere'"));
  34.     static ConstructorHelpers::FObjectFinder<UMaterial> Material_Blue(TEXT("MaterialInstanceConstant'/Game/StarterContent/Materials/M_Water_Lake.M_Water_Lake'"));
  35.  
  36.     MovementComp = ObjectInitializer.CreateDefaultSubobject<UMovementComponentDlaPawna>(this, TEXT("MovementComp")); //
  37.  
  38.     MeszkaPawna->SetCollisionProfileName("BlockAll");
  39.     //MeszkaPawna->SetSimulatePhysics(true);
  40.     MeszkaPawna->SetStaticMesh(StaticMesh.Object);
  41.     MeszkaPawna->SetMaterial(0, Material_Blue.Object);
  42.     RootComponent = MeszkaPawna;
  43.  
  44.     AIControllerClass = AMyAIController::StaticClass();
  45.  
  46.     PrimaryActorTick.bCanEverTick = true;
  47.  
  48.  
  49. }
  50.  
  51. ///////////////////////////////////////////////////////////////
  52.  
  53. And the custom movement component
  54.  
  55. .h
  56.  
  57. UCLASS()
  58. class NIEMAMJUZSILY_API UMovementComponentDlaPawna : public UCharacterMovementComponent
  59. {
  60.     GENERATED_BODY()
  61.    
  62.     virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
  63.    
  64.    
  65. };
  66.  
  67. .cpp
  68.  
  69. void UMovementComponentDlaPawna::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
  70. {
  71.     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
  72.  
  73.     if (GEngine) GEngine->AddOnScreenDebugMessage(FMath::Rand(), 5.f, FColor::Yellow, FString("Movement Component Tick")); // this is NOT called
  74. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement