UE4里有弹丸的MovementComponent,十分明显需要这个。
但是魂类呢?放在Tick里,我已经实现了,但是总感觉是对资源的浪费
于是
从Learning.C++.by.Creating.Games.with.UE4.2015上复制下来的简单怪物AI代码,
void AMonster::Tick(float DeltaSeconds)
{ Super::Tick( DeltaSeconds ); // basic intel: move the monster towards the player AAvatar *avatar = Cast<AAvatar>( UGameplayStatics::GetPlayerPawn(GetWorld(), 0) ); if( !avatar ) return; FVector toPlayer = avatar->GetActorLocation() - GetActorLocation(); toPlayer.Normalize(); // reduce to unit vector // Actually move the monster towards the player a bit AddMovementInput(toPlayer, Speed*DeltaSeconds); // At least face the target // Gets you the rotator to turn something // that looks in the `toPlayer` direction FRotator toPlayerRotation = toPlayer.Rotation(); toPlayerRotation.Pitch = 0; // 0 off the pitch RootComponent->SetWorldRotation( toPlayerRotation );}看了一下,感觉魂类用ProjectileMovement会比较好,如果需要让物体不停旋转用RotatingMovement
可以少些很多东西
2016.4.6
发现CrowdFollowingComponent,以后可以试着用一下