Hi,
I’m trying to create an “energy shield”-effect for my player pawn (like the big blue bubbles in Star Wars or the shield of the droideka) which should be attached to the player itself. The player should be able to activate the shield and walk around it whilst it is surrounding him.
Everything is working accordingly but one thing: I can’t get the shield to work when it’s attached to the player.
My plan was to have the player spawn a shieldactor and let it handle all the collision as long as it exists.
I started by creating a new class derived from AActor and called it PlasmaShield. I added a static mesh component for the visual representation of the shield and also for collision detection. When a new shield instance is created it performs some required steps:
It sets its rotation to absolute, adds it’s owner to the array of “IgnoreActorWhenMoving” so it wont cause any problems with the collision of the player (who is inside of the shield). Then I attach the collision component of the shield to the root component of the player.
void APlasmaShield::Activate(AActor* NewOwner)
{
SetOwner(NewOwner);
if (Owner)
{
ABrawlingPawn* MyPawn = Cast <ABrawlingPawn>(Owner);
if (MyPawn)
{
MyPawn->SetHasShield(true);
}
//attach to owner's root component
USceneComponent* Body = Owner->GetRootComponent();
MeshComp->bAbsoluteRotation = true;
MeshComp->AttachTo(Body, "");
MeshComp->IgnoreActorWhenMoving(Owner, true);
FTimerHandle TimerHandle;
GetWorldTimerManager().SetTimer(TimerHandle, this, &APlasmaShield::Deactivate, LifeTime-0.5, false);
PlaySound(openSound);
TimeLine.ReverseFromEnd();
}
}
And I guess the attaching is, what’s wrong. I’ve read that when I attach an actor to another actor only one collision component can be active at all times. So since the shield is attached to the player and not the other way around, the shield doesn’t register any collisions as it updates it position. Just the player’s collision component is registering those. As long as the shield is not attached it works great, but I want it to move with the player.
How would I go for it? I mean this must’ve been achieved before as it is a quite simple idea.
One approach could be to attach the player to the shield, but what would I do about the movement input which the player receives? I also could set the box extend of my player’s collision to a heigher value to simulate the shield but then the whole concept of having it as an extra class would be stupid imo.
Can someone provide me some insight here?
P.S:
After reading a little bit further I found this thread: Collision when using attached actors - World Creation - Unreal Engine Forums
This seems to be quite the same problem but doesn’t help much since I also want the collision to be correct (for example not fitting through a narrow space when the shield is activated).
~Theo