Physics Handle not grabbing like it is supposed to

Hello, i have a projectile (like an arrow) that, when overlapping a character, creates a Physics Handle Component to grab it by the hit bone (using the GetBoneLocation as GrabLocation) and on every tick update the target location to the origin of the projectile. This should make the hit bone to be always in the origin, but in most bones that is not the case. If i hit the character on the chest it mostly works as long as i use GetBoneLocation instead of Hit.Location for the GrabLocation:

The biggest problem are the arms and the head, because for some reason it creates a huge offset:

57879-arrow+2.png

If i eject and lift the projectile (to make sure it’s not the wall collision creating the offset) you can clearly see that:

57880-arrow+3.png

Here is what i used in code:

.h

TArray<UPhysicsHandleComponent *> PhysicsHandles;

.cpp

void AArrowProjectile::OnOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & Hit)
{
    USkeletalMeshComponent * SkeletalMesh = Cast<USkeletalMeshComponent>(OtherComp);

    UPhysicsHandleComponent * PhysicsHandle = NewObject<UPhysicsHandleComponent>(this);

	PhysicsHandle->RegisterComponent();

	PhysicsHandles.AddUnique(PhysicsHandle);

    // Although it would be better to use Hit.Location here to be more accurate, GetBoneLocation creates a lot less offsets.

	PhysicsHandle->GrabComponent(SkeletalMesh, Hit.BoneName, SkeletalMesh->GetBoneLocation(Hit.BoneName), true);
}

void AArrowProjectile::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	for (UPhysicsHandleComponent * PhysicsHandle : PhysicsHandles)
		PhysicsHandle->SetTargetLocation(RootComponent->GetComponentLocation());
}

I’m using 4.9 from the release branch. If needed i can supply a project for you to see the issue.

Hey -

If possible could you provide a sample project so I can see exactly what the issue is? Looking at the screenshots I can’t determine what you’re referring to as your “arrow” nor can I see where it’s supposed to attach to the skeletal mesh. When you post the sample project please be sure to indicate what the expected behavior is so I know exactly what to look for.

Cheers

I have uploaded a project with the problem i’m experiencing:

Just point to the chest and shoot, you’ll see that it sticks where it should. If you shoot an arm or head usually you get a big offset between the projectile and the body part that was hit. You can also eject the gameplay and select the projectile and lift it up so it doesn’t have the wall behind him, you’ll see that in the chest the spring works well and the character stays close to the area that was shot, but on the arms/head you get the offset. I’m not sure if this behavior is intended, but when i do the GrabComponent command i give the grab location as the Bone Location and the Bone Name itself, shouldn’t it always try to put that bone on the target location (which is, in this case, the root of the projectile)?

Hey -

I noticed the offset you mentioned when testing the project and have submitted a report (UE-21101) for further investigation.

Cheers

Thank you very much, please keep me posted :slight_smile:

Is there any update regarding this issue? Thank you.

Hey -

We were unable to setup a reproduction from a clean project and we’ve not seen this happening in other projects. Because of this, UE-21101 is currently a low priority for the developers while they focus on more major crashes and other widespread bugs.

The project i’ve sent you was from a clean project so it’s easy to replicate, i can tell you the steps. I really needed this to be working for my game. Currently i’m doing this to grab:

PhysicsHandle->GrabComponent(SkeletalMesh, Hit.BoneName, SkeletalMesh->GetBoneLocation(Hit.BoneName), true);

But that location is in world space, so if the character moves or rotates won’t the bonelocation be outdated and create the offsets i’m experiencing?

I’ve created a new project and set the code to match what the code from your sample project looks like. What would be the next step to matching the setup in the sample project? I’ve matched the layout of the projectile blueprints however when I fire my projectile it will bounce off walls rather than sticking to them. Can you let me know what needs to be done to mirror the setup you used?

You have to turn off Should Bounce on the Projectile Component.

Make sure the collision settings for the CollisionComp is as follows:

Same thing for the capsule collision component and mesh of the enemy:

Hey -

I am still investigating the GrabComponent offset. I did notice that if the shoulder is shot the body with shift to where the projectile is in the center of the body. I have not found a cause yet however it appears that the location of the bone is not being correctly. I will update you when I have more information.

Cheers

The problem i think must be on:

PhysicsHandle->GrabComponent(SkeletalMesh, Hit.BoneName, SkeletalMesh->GetBoneLocation(Hit.BoneName), true);

Because drawing a debug directional arrow for the TargetLocation shows that it’s fine. I tried replacing SetTargetLocation with SetTargetLocationAndRotation(GetActorLocation(), GetActorForwardVector().Rotation()); so it’s more accurate in the rotation, but that didnt change anything.

I’ve tried looking into the code for GrabComponent but i don’t understand much of Physx code. When you specify the GrabLocation and the bone, are you saying “i’m going to grab on the bone with the offset of the difference between the current bone’s location and the GrabLocation”, if that’s the case then it makes sense the problem i’m experiencing because we never update GrabLocation so the offset will only get bigger and bigger as the enemy is being dragged into the arrow. To fix this wouldn’t it make more sense to add another call to GrabComponent but instead of setting a world location, you set the offset location (and maybe offset rotation) in bone or mesh space so he knows always what’s the distance to mantain? As an alternative we could update the GrabLocation in the Tick event, but i’m not sure that would work properly.

Hey -

After further investigation I found something interesting. It seems that what is set as the OtherComp in the OnOverlap function of your projectile code does not match the OtherComp pin of the ComponentBeginOverlap blueprint node. Using the blueprint node to print out the name of the OtherComp, it is shown as “Enemy_C_#.CharacterMesh0 SK_Mannequin” where the # represents which enemy is being hit. On the other hand, printing the name of OtherComp from code simply prints “CharacterMesh0” for all enemies.

I have yet to fully setup the behavior in blueprints however considering your physics handle is being set based on the skeletal mesh bone, this difference may be connected to the offset. Let me know if this information helps at all or if you have any further information to add.

Maybe the skeletal mesh has 2 different print functions when called from blueprints (Get Display Name) and from code, but the result appears to be the same, so unfortunately i don’t think that is related to the problem :S

Hey -

I have not found a solution to the offset using physics handles however I did come across a video for setting up projectiles that impale into an enemy hit. The video focuses on blueprints but should be able to be converted to code.

In this case they are deleting the projectile when it hits the enemy and spawning a mesh already attached to the bone hit. Can you let me know if the information presented in the video is helpful in setting up your impale system?

I had already seen that video, but that only covers the sticking of the projectile to the enemy. I already have that working, what i’m interested in having is the enemy go into ragdoll and have the projectile drag the body along, just like the stake gun in painkiller.

Hello ,

I looked into this after seeing your problem and it seems that this issue is being caused by the default Linear Stiffness that is set in a PhysicsHandle. By default, physics handles aren’t suppose to be this ‘strict’. They’re meant to be loose and allow physics to do its thing so the mass of the skeletal mesh (which is centered if shot in the chest of course) was causing the offset. If you set the Linear Stiffness to a high number in code prior to the GrabComponent line, it should give you the results you’re looking for. As far as what I mean by high, 10,000 seemed about right but was still a bit off for certain body parts. You may also want to take a look at changing Linear Dampening for the jerking actions of it all since it is rather fast. The same goes for Angular Dampening/Stiffness.

Hope this helps, please be sure to let me know if it works for you.

Thank you for your feedback, i will try it out and let you know :slight_smile:

Hey -

I just wanted to touch base and see if you’ve had the chance to try making the chances that mentioned? Let us know if you have any further questions.

I’ve tried it out and indeed it looks much better, i will play with the values, but i think it’s a good enough solution for now, thank you :slight_smile: