How to pickup a "physical" weapon which has collosion, and animating the pickup action, while upper body is Ragdoll?

how to pickup a “physical” weapon which has collosion, and animating the pickup action, while upper body is Ragdoll?
Socket doesn’t have the pickup animation, and can only pickup staticMesh disabled collision.
The charactor was half-ragdoll as the following tutorial:

Sockets and bones are the same if you want to attach something. Both can move with the animation. Well at one point you know you want to pickup something, then disable collisions. Check it by yourself in overlap callbacks or switch to another profile “pickable”. Maybe there are even more options.

thanks. then how to enble collison of the picked up object after it was picked up. eg.the player pick up a stick, then it can use that stick to hit other players as a weapon.

If you picked it up, it should be attached to the parent actor. In the overlap method you can check if the weapon collides with the current parent actor and ignore that collision by just doing nothing. Otherwise all overlaps and collisions will react like you want it to.

There might be some other ways to solve it, but that’s a pretty forward way to handle it.

thanks. normally this kind of method will be better used in C++ or Blurprint ?

could you please give a example of what’s the name of the overlap method?thanks! use C++ or Blueprint at this point is better?thanks!

In your Header (.h) file:

virtual void OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

In your Source (.cpp) file:

void AProjectile::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { }

Just as an example on how I check my projectile collisions:

bool AProjectile::ValidateCollision(class UPrimitiveComponent* Component, class AActor* OtherActor)
{
	AActor* owner = this->GetOwner();
	if (IsValid(owner)) {
		if (OtherActor == owner || OtherActor->IsAttachedTo(owner) || owner->IsAttachedTo(OtherActor)) {
			//UE_LOG(LogTemp, Warning, TEXT("[AProjectile::ValidateCollision] Ignored owner"));
			return false;
		}

		if (!IsValid(WeaponizeComponent) || !WeaponizeComponent->CanAttack(OtherActor)) {
			//UE_LOG(LogTemp, Warning, TEXT("[AProjectile::ValidateCollision] Friendly fire"));
			return false;
		}
	}

	return true;
}

It will be better if you can do it in C++. Worth learning and trying it.

thank you very much!

Don’t forget to setup your Collision Presets in the Project Settings and use this for the Actors you are using.

This is how my setup (in the constructor from projectile class) looks like:

// Use a sphere as a simple collision representation.
CollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
CollisionComponent->BodyInstance.SetCollisionProfileName(TEXT("Projectile"));
CollisionComponent->SetSimulatePhysics(false);
CollisionComponent->SetEnableGravity(false);
// Set the sphere's collision radius.
CollisionComponent->InitSphereRadius(10.0f);
// OnHit callback
CollisionComponent->OnComponentHit.AddDynamic(this, &AProjectile::OnHit);
CollisionComponent->OnComponentBeginOverlap.AddDynamic(this, &AProjectile::OnOverlapBegin);

// Set the root component to be the collision component.
RootComponent = CollisionComponent;

Thanks so so so much!
is this for the PlayerCharactor(1stPerson & 3rdPerson), right?

This is just an example on how to use custom collision handling. In my example I show handling a projectile that can detect if the collision is from the own player that is shooting this projectile (GetOwner) and it can detact friendly fire. You have to check how this can be adjusted for your needs, technically it is very similar.

thanks1

1 Like