Making custom pawn physics

Is there any way to use built-in ue4 object physics to interact with my custom pawn? My pawn(character) doesn’t use physics to move, it just updates coordinates each frame based on user input and gravity vector. i.e. FVector (UserInputX, UserInputY, GravityVector).
Clearly pawn simulates no physics to move, so is there any way to make it interact with physics objects to push it around? Or should I calculate hit normal each time and recalculate new expected position for swept object? (Making physics by myself).

1 Like

Look at “Character Movement Component” code you will find all what you need to make a non-physical pawn interact with other rigid bodies

You can bind hit event from you collision component , and use something similar to this

CharacterMovementComponent.cpp

 if (!bEnablePhysicsInteraction)
    	{
    		return;
    	}
    
    	if (OtherComp != NULL && OtherComp->IsAnySimulatingPhysics())
    	{
    		const FVector OtherLoc = OtherComp->GetComponentLocation();
    		const FVector Loc = UpdatedComponent->GetComponentLocation();
    		FVector ImpulseDir = FVector(OtherLoc.X - Loc.X, OtherLoc.Y - Loc.Y, 0.25f).GetSafeNormal();
    		ImpulseDir = (ImpulseDir + Velocity.GetSafeNormal2D()) * 0.5f;
    		ImpulseDir.Normalize();
    
    		FName BoneName = NAME_None;
    		if (OtherBodyIndex != INDEX_NONE)
    		{
    			BoneName = ((USkinnedMeshComponent*)OtherComp)->GetBoneName(OtherBodyIndex);
    		}
    
    		float TouchForceFactorModified = TouchForceFactor;
    
    		if ( bTouchForceScaledToMass )
    		{
    			FBodyInstance* BI = OtherComp->GetBodyInstance(BoneName);
    			TouchForceFactorModified *= BI ? BI->GetBodyMass() : 1.0f;
    		}
    
    		float ImpulseStrength = FMath::Clamp(Velocity.Size2D() * TouchForceFactorModified, 
    			MinTouchForce > 0.0f ? MinTouchForce : -FLT_MAX, 
    			MaxTouchForce > 0.0f ? MaxTouchForce : FLT_MAX);
    
    		FVector Impulse = ImpulseDir * ImpulseStrength;
    
    		OtherComp->AddImpulse(Impulse, BoneName);
    	}

Thank you very much, this method of calculating impulse looks really interesting, I will definitely try to implement it.