Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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).

Product Version: UE 4.9
more ▼

asked Sep 17 '15 at 10:44 AM in C++ Programming

avatar image

74 12 16 21

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Sep 17 '15 at 11:12 AM

avatar image

3.4k 152 28 317

avatar image Mhousse1247 Sep 17 '15 at 11:30 AM

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


  if (!bEnablePhysicsInteraction)
         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;
             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);
avatar image Unteroid Sep 17 '15 at 11:42 AM

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

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question