Edit: After further testing the value of the impact normal is changing after being passed to the multicast function.
I am trying to add an impulse to my character upon death that is dependent upon the direction which they were shot from. From the weapon I create the FPointDamageEvent to store the information needed to apply the impulse.
FPointDamageEvent DamageEvent = FPointDamageEvent(Damage, LastHit, AimDirection, UDamageType::StaticClass());
LastHit.GetActor()->TakeDamage(DamageEvent.Damage, DamageEvent, MyCharacter->Controller, this);
If the damage taken was lethal my Die method is called.
/** Kills the character. */
void Die(struct FDamageEvent const & DamageEvent, AController* Killer);
Die then calls a MultiCast method, MultiDie, which is responsible for rag-dolling the character on the clients and applying the directional impulse.
void AOneFlagCharacter::MultiDie_Implementation(struct FDamageEvent const & DamageEvent, AController * Killer)
{
if (GetNetMode() != ENetMode::NM_DedicatedServer || Role < ROLE_Authority) {
GetMesh()->SetAllBodiesSimulatePhysics(true);
GetMesh()->SetSimulatePhysics(true);
GetMesh()->WakeAllRigidBodies();
if (DamageEvent.IsOfType(FPointDamageEvent::ClassID)) {
const FPointDamageEvent* MyPointDamageEvent = (FPointDamageEvent*)&DamageEvent;
FVector impulseDirection = MyPointDamageEvent->HitInfo.ImpactNormal.GetSafeNormal();
GetMesh()->AddImpulse(impulseDirection * GetMesh()->GetBodyInstance()->GetBodyMass() * 100000.0f);
}
}
}
It is in MultiDie that I am not sure what the error is. My first issue is that the ‘IsOfType’ if statement is not evaluating to true. However, if I comment out the if statement, the values in my ImpactNormal are always the same and nearly zero. For example, ImpactNormal.Y: 2.66247e-43. I am guessing that something is going wrong when I cast to an FPointDamageEvent. Any help is greatly appreciated.