133{
135
136 if (World == nullptr)
137 {
138 return;
139 }
140
141 TArray<FOverlapResult> Overlaps;
142 FCollisionQueryParams QueryParams(SCENE_QUERY_STAT(WeaponPullBehavior), false);
143
145 {
146 QueryParams.AddIgnoredActor(Avatar);
147 }
148
149 World->OverlapMultiByChannel(Overlaps, Center, FQuat::Identity,
PullOverlapChannel, FCollisionShape::MakeSphere(Radius), QueryParams);
150
151 if (Overlaps.IsEmpty())
152 {
153 return;
154 }
155
156 TArray<AEnemyCharacterBase*> ValidEnemies;
157
158 for (const FOverlapResult& Overlap : Overlaps)
159 {
161
162 if (Enemy ==
nullptr || Enemy->
IsDead() ==
true)
163 {
164 continue;
165 }
166
167 if (ValidEnemies.AddUnique(Enemy) == INDEX_NONE)
168 {
169 continue;
170 }
171
172 FVector PullDirection = Center - Enemy->GetActorLocation();
173 PullDirection.Z = 0.0f;
174 PullDirection = PullDirection.GetSafeNormal();
175
176 if (PullDirection.IsNearlyZero())
177 {
178 continue;
179 }
180
181 const FVector CurrentVelocity = Enemy->GetVelocity();
182 const FVector TargetVelocity = PullDirection *
PullStrength;
183 FVector NewVelocity(CurrentVelocity.X, CurrentVelocity.Y, 0.0f);
184 NewVelocity = FMath::VInterpTo(NewVelocity, TargetVelocity, DeltaTime,
PullInterpSpeed);
185 Enemy->LaunchCharacter(NewVelocity, true, false);
186 }
187}
virtual bool IsDead() const
Definition CharacterBase.cpp:65
Definition EnemyCharacterBase.h:49
float PullInterpSpeed
Definition WeaponBlackholeAction.h:91
float PullStrength
Definition WeaponBlackholeAction.h:88
TEnumAsByte< ECollisionChannel > PullOverlapChannel
Definition WeaponBlackholeAction.h:94