まずは追いかけ具合はこんな感じ
まず BluePrintからActorで適当にAI Gorl アクターを作る

Charactor BPに設定する
AI ControllerでAI Gorl ActorをSpawnする。

Tickで

Line Trace by Channel

つづいてジャンプの前処理処理

ジャンプ

できたパッケージはこちらにアップしました。できたら遊んでみてください。
2.83GBあります。
download は以下
DevelopmentBuild チェックポイント(レベル内セーブ機能)があるEasyバージョン
V7 VoicePeak版
https://drive.google.com/file/d/1brxO2bYWV4GZfw9vMK6O_L6ReHHHTFow/view?usp=sharing
V4
https://drive.google.com/file/d/1S25uUMd1k9umFNJ8HRiXHf0QvtRGCTNR/view?usp=sharing
Shipping チェックポイント(レベル内セーブ機能)がないHardバージョン
V6 VoicePeak版
https://drive.google.com/file/d/1khzi3AEROpcaJhmpsGoMqxYDtxVVFj9U/view?usp=sharing
V2
https://drive.google.com/file/d/10s3s-XBcIw3ezOFC3qbgvrI82PXvzn2W/view?usp=sharing
操作方法
キーボードでの操作は以下
Jump スペースバー
スライディング C
弓構え 1
弓発射 マウス左クリック
このレ ベルをやり直し H
キャラクター変更 C
移動 WASD 後ろから敵に近づくと、はがいじめ
カメラ方向 マウス左クリックドラッグ
アイテム回収/構え時は投げ マウス左クリック
アイテム投げ構え マウス右クリック
ゲームパッドでの操作は以下
感想、コメントなどくれると泣いて喜びます。笑
NavMeshを配置して
表示できるようにします。
表示されました。
ブラシセッティングで広げます。
BP_ShooterAIControllerを開いてPathFollowingComponentが作用しているからです。
C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime\AIModule\Classes\AIController.h
MoveToを見ると
MoveToActor
MoveToLocation
MoveTo
の3つがあります。
/** AIを指定されたゴールアクターに向けて移動させ(宛先は継続的に更新されます)、
次のアクティブなパスを中止します
* @ paramAcceptanceRadius-ポーンが十分に近づいたら移動を終了します
* @ parambStopOnOverlap-ポーンの半径をAcceptanceRadiusに追加します
* @param bUsePathfinding-ナビゲーションデータを使用してパスを計算します
(そうでない場合は直線になります)
* @param bCanStrafe-フォーカス関連フラグを設定します:bAllowStrafe
* @ paramFilterClass-パスファインディング調整用のナビゲーションフィルター。
指定されていない場合、DefaultNavigationFilterClassが使用されます
* @ parambAllowPartialPath-目標に到達できない場合は不完全なパスを使用します
* @note AcceptanceRadiusは、ヘッダーパーサーが
UPathFollowingComponent :: DefaultAcceptanceRadiusを認識できないため、
デフォルト値または-1になります。*/
UFUNCTION(BlueprintCallable, Category = "AI|Navigation", Meta = (AdvancedDisplay = "bStopOnOverlap,bCanStrafe,bAllowPartialPath"))
EPathFollowingRequestResult::Type MoveToActor(AActor* Goal, float AcceptanceRadius = -1, bool bStopOnOverlap = true,
bool bUsePathfinding = true, bool bCanStrafe = true,
TSubclassOf<UNavigationQueryFilter> FilterClass = NULL, bool bAllowPartialPath = true);
なので
\ShooterAIController.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "ShooterAIController.h"
#include "Kismet\GameplayStatics.h"
void AShooterAIController::BeginPlay()
{
Super::BeginPlay();
APawn* PlayerPawn= UGameplayStatics::GetPlayerPawn(GetWorld(),0);
SetFocus(PlayerPawn);
MoveToActor(PlayerPawn,200);
}
これでプレイしてみると一度動きます。が一度しかついてきません。
C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime\Engine\Classes\GameFramework\Actor.h
virtual void Tick( float DeltaSeconds );
をコピーしてShooterAIController.hにTickをオーバーライドしてこうしました。
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "ShooterAIController.generated.h"
/**
*
*/
UCLASS()
class SIMPLESHOOTERCP2_API AShooterAIController : public AAIController
{
GENERATED_BODY()
public:
virtual void Tick( float DeltaSeconds ) override;
protected:
virtual void BeginPlay() override;
};
C:\Download\Game\SImpleShooter\SImpleShooterCp2 4.26\Source\SImpleShooterCp2\ShooterAIController.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "ShooterAIController.h"
#include "Kismet\GameplayStatics.h"
void AShooterAIController::BeginPlay()
{
Super::BeginPlay();
//APawn* PlayerPawn= UGameplayStatics::GetPlayerPawn(GetWorld(),0);
}
void AShooterAIController::Tick(float DeltaSecond)
{
APawn* PlayerPawn= UGameplayStatics::GetPlayerPawn(GetWorld(),0);
SetFocus(PlayerPawn);
MoveToActor(PlayerPawn,200);
}
NavMeshを広げておかないとAIキャラクターが歩きにくいみたいです
できたのがこれ、
AIキャラクターが回転しないバグは次のときに説明するみたい。
Control + P でAIControllerと入力して
UE_4.26\Engine\Source\Runtime\AIModule\Classes\AIController.h
を開きます。
/* 特定の優先度にフォーカスアクターを設定し、結果としてFocalPointを設定します。*/ virtual void SetFocus(AActor* NewFocus, EAIFocusPriority::Type InPriority = EAIFocusPriority::Gameplay);
/ *特定の優先度にフォーカスアクターを設定し、結果としてFocalPointを設定します。 * /
/* Set Focus actor for given priority, will set FocalPoint as a result. */
virtual void SetFocus(AActor* NewFocus, EAIFocusPriority::Type InPriority = EAIFocusPriority::Gameplay);
こっちは
指定された優先度のフォーカスをクリアし、結果としてFocalPointもクリアします@paramInPriorityフォーカス優先度をクリアします。 何を使用すればよいかわからない場合は、おそらくEAIFocusPriority :: Gameplay * /を意味します。
virtual void ClearFocus(EAIFocusPriority::Type InPriority);
/** 指定された優先度のフォーカスをクリアし、結果としてFocalPointもクリアします
* @paramInPriorityフォーカス優先度をクリアします。 何を使用すればよいかわからない場合は、おそらくEAIFocusPriority :: Gameplay * /を意味します。*/
virtual void ClearFocus(EAIFocusPriority::Type InPriority);
フォーカスの優先度ってなによってなるので見てみると
その列挙型の定義を見てみると、デフォルトの動きとMoveとゲームプレイがあることがわかります
そしてそれらは基本的に優先順位の順にリストされています。
//これが通常の列挙型ではなく名前空間である理由は
//ゲーム固有のコードで拡張できるようにする
// @todoこれは少し面倒なので、リファクタリングする必要があります
namespace EAIFocusPriority
{
typedef uint8 Type;
const Type Default = 0;
const Type Move = 1;
const Type Gameplay = 2;
const Type LastFocusPriority = Gameplay;
}
struct FFocusKnowledge
{
struct FFocusItem
{
TWeakObjectPtr<AActor> Actor;
FVector Position;
FFocusItem()
{
Actor = nullptr;
Position = FAISystem::InvalidLocation;
}
};
TArray<FFocusItem> Priorities;
};
私たちは主にこのゲームプレイを使用するので、それらをあまり使用する必要はありませんでした
次に
UE_4.26\Engine\Source\Runtime\Engine\Classes\GameFramework\Actor.h
の
protected:
/** Overridable native event for when play begins for this actor. */
virtual void BeginPlay();
をコピーして
ShooterAIController.hにペーストしてオーバーライドします
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "ShooterAIController.generated.h"
/**
*
*/
UCLASS()
class SIMPLESHOOTERCP2_API AShooterAIController : public AAIController
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
};
C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime\Engine\Classes\Kismet\GameplayStatics.h
の
/** 指定されたプレーヤーインデックスのプレーヤーポーンを返します */
UFUNCTION(BlueprintPure, Category="Game", meta=(WorldContext="WorldContextObject", UnsafeDuringActorConstruction="true"))
static class APawn* GetPlayerPawn(const UObject* WorldContextObject, int32 PlayerIndex);
をみると指定されたプレーヤーインデックスのプレーヤーポーンを返しますので
// Fill out your copyright notice in the Description page of Project Settings.
#include "ShooterAIController.h"
#include "Kismet\GameplayStatics.h"
void AShooterAIController::BeginPlay()
{
Super::BeginPlay();
APawn* PlayerPawn= UGameplayStatics::GetPlayerPawn(GetWorld(),0);
SetFocus(PlayerPawn);
}
できたのがこれ
新規C++クラスを作る 親クラスにAIコントローラーを選ぶ
名前は ShooterAIController
このクラスを使ってブループリントクラスを作る
名前を BP_ShooterAIController
BP_ShooterCharacterを開いて ポーンのAI ContrallerClassにBP_ShooterAIControllerを設定
実行してBP_ShooterAIControllerがポーンされてるか確認する。