The behavior you described suggests that the player is ragdolling due to an OnComponentHit event that gets triggered not just by the floor but by any collision with a solid object.
Here’s a step-by-step guide to achieve the desired behavior:
- Make sure your player’s collision is set up correctly:
- Your player’s CapsuleComponent should be set to block all by default.
- The mesh (assuming it’s a skeletal mesh) should be set to No Collision by default.
- When you switch to ragdoll, you’ll enable collision on the mesh and disable it on the CapsuleComponent.
- Set up your floor Blueprint correctly:
- Make sure that the OnComponentHit event on the floor Blueprint specifically checks if the actor it collided with is the player. You can do this by using the “Cast To” node in Blueprints.
- In the BP_ThirdPersonCharacter:
- Make a custom event or function that switches the character to ragdoll. This event/function should:
- Disable collision and physics simulation on the CapsuleComponent.
- Enable collision and physics simulation on the character’s skeletal mesh.
- Optionally set all the physical animation weights to 0 to fully ragdoll the character.
- Call this event/function only when the specific condition is met (e.g., the character hits the floor).
- In your floor Blueprint:
- On the OnComponentHit event:
- Use “Cast To BP_ThirdPersonCharacter” on the hit actor. If the cast is successful, it means the player character collided with the floor.
- Call the ragdoll custom event/function on the BP_ThirdPersonCharacter.
- To avoid the character from ragdolling when hitting walls or other objects:
- Ensure that the OnComponentHit event in your floor Blueprint is the only one triggering the ragdolling. Other objects in your scene should not inadvertently call the ragdoll event.
Remember, if you’re using a OnComponentHit event, it can be triggered by any hit unless you specify a particular actor or object. So, always double-check which actor or component triggers the event and under which conditions.
Lastly, consider the order of operations. If you’re checking for a collision in both the player and the floor, there could be conflicting behaviors. Try to centralize the logic, either handle the collision entirely in the character blueprint or entirely in the floor blueprint, to avoid unexpected outcomes