NavigationHandleはControllerクラスで既に定義されているので、
それを使えばいいと思います。
(例)Pathを見つけたい場合の命令: NavigationHandle.FindPath();
デバッグ目的での「マップ上に目的地までの誘導ラインを描画」という機能は、
NavigationHandle.DrawPathCache();
もしくは
DrawDebugLine();
辺りで可能だと思います。(下記コード参照)
PathCacheは
NavigationHandle.PathCache
で参照できるんじゃないかと思います。
(私はそこまで使ってないので分かりませんが)
参考までに、UTBotクラスを拡張した、MoveToward()を含むサンプルコードを以下に記してお きます。
(いろんなところからの寄せ集めで、私自身よく分かってない部分もありますが)
Code:
class MyGameBot extends UTBot;
var Actor MoveTowardDestActor, MoveTowardFocusActor;
var Vector TempDest;
var float DestinationDistance;
var float StopDistance;
function BeginMoveToward(Actor Dest, Actor ViewFocus)
{
MoveTowardDestActor = Dest;
MoveTowardFocusActor = ViewFocus;
GotoState('Chase');
}
//Chases the destination actor using direct movetoward if dest-actor is reachable and pathfinding if not
state Chase
{
//Gets the navmesh path to the dest-actor
function bool FindNavMeshPath()
{
// Clear cache and constraints (ignore recycling for the moment)
NavigationHandle.PathConstraintList = None;
NavigationHandle.PathGoalList = None;
//Create constraints
class'NavMeshPath_Toward'.static.TowardGoal( NavigationHandle, MoveTowardDestActor);
class'NavMeshGoal_At'.static.AtActor( NavigationHandle, MoveTowardDestActor);
//Find path
return NavigationHandle.FindPath();
}
event SeePlayer(Pawn SeenPlayer)
{
//Todo:処理を追加
}
event HearNoise(float Loudness, Actor NoiseMaker, optional Name NoiseType )
{
//Todo:処理を追加
}
function Rotator GetAdjustedAimFor( Weapon InWeapon, vector ProjStart )
{
//Todo:エイム誤差を追加
//(これがないと100%100中になってしまう)
return Rotation;
}
Begin:
//Check if the destination actor is within end of chase range
DestinationDistance = VSize( Pawn.location - MoveTowardDestActor.location);
if (DestinationDistance < StopDistance)
GotoState('Roaming');
else if (NavigationHandle.ActorReachable(MoveTowardDestActor))
{
FlushPersistentDebugLines();
//The dest-actor is reachable so move towards him
MoveToward( MoveTowardDestActor, MoveTowardFocusActor, 100);
}
else if (FindNavMeshPath())
{
//The dest-actor is not reachable so use the navmesh path move towards him
NavigationHandle.SetFinalDestination(MoveTowardDestActor.Location);
FlushPersistentDebugLines();
// NavigationHandle.DrawPathCache(, true);//パスを画面に描画する(デバッグ用)
if (NavigationHandle.GetNextMoveLocation(TempDest, Pawn.GetCollisionRadius()))
{
// DrawDebugLine(Pawn.Location, TempDest, 0, 255, 0, true);//パスの線を画面に描画する(デバッグ用)
MoveTo(TempDest, MoveTowardDestActor);
}
}
else
{
//We can't get to the dest-actor so just go back to begin Idle.
GotoState('Roaming');
}
goto 'Begin';
}
defaultproperties
{
StopDistance=250
NavigationHandleClass=class'NavigationHandle'
}
ただし、上記コードでは複数キャラを同時にMoveTowardさせた場合、
私の環境ではうまくいかないことがあります。
どの辺が問題なのかは分かっていませんが、その辺はご了承下さいませ。
NavigationMeshを使用すると、UTBotのコードのままではMoveToward中には攻撃 しなくなります。
なので、その辺りの攻撃処理もSeePlayer、HearNoiseなどで組み込んでおく必要があります 。
また、向いている方向を指定している場合、攻撃が100発100中になってしまうので、
適当にRotationを調整する命令も必要かと思います。
他にもいろいろ機能を含めて実装するとなると、
私のコードでは最終的に500lineぐらいの量を書く必要がありました。
後は、注意が必要なのは、NavMeshを使うと、そのBotはPathNode探索はしなくなるようです 。
なので、NavMeshとPathNode探索の両方の機能を使う場合、
DefaultGame.iniに以下の命令を追加すればできます。
Code:
[UnrealEd.EditorEngine]
bBuildReachSpecs=True
参考にして下さいませ。
Bookmarks