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"

AddForce/AddImpulse won't work

Hey everyone,

I've created a Pawn class in C++, added a Mesh component and set physics simulation to true, as well as defining a physics profile to the Mesh (When I skipped this part, gravity wasn't affecting the object). I used "Pawn".

Now, I'm trying to AddForce on the Tick function, but don't matter how big I make the force vector, the mesh simply won't move.

The object is falling when I hit play, which means physics are being simulated, but Force/Impulse doesn't get applied. I tried this both with Blueprints and C++.

When I use SetLinearVelocity, it works, but then gravity doesn't affect the object.

I'm having a lot of issues with Physics with Unreal. Hope someone can help me out with this.

Here is my constructor code:

 // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
 PrimaryActorTick.bCanEverTick = true;
 // Setting the skeletal mesh to be the root.
 mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Skeletal Mesh"));
 RootComponent = mesh;

And here's the Tick function:

 Super::Tick( DeltaTime );
 mesh->AddForce(mesh->GetRightVector() * 10000);

Pretty basic stuff which should be working fine, I think.

Well, if someone can give me a hand with this, I'd really appreciate.


Product Version: UE 4.8
more ▼

asked Aug 25 '15 at 09:23 PM in C++ Programming

avatar image

Guto Thomas
3 3 6 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Try This

 mesh->AddForce(FVector::RightVector * mesh->GetBodyInstance()->GetBodyMass() * 1000);
more ▼

answered Aug 25 '15 at 09:46 PM

avatar image

3.5k 152 29 318

avatar image Guto Thomas Aug 25 '15 at 09:56 PM

Thanks, Mhousse1247, it worked! now I'm trying to understand why. If I don't multiply by the mass, it assumes it's 0 and makes the whole thing a zero vector? Or the mass then makes the vector something that's big enough in size?

avatar image Mhousse1247 Aug 25 '15 at 10:01 PM

myabe "mesh->GetRightVector()" is facing the ground

There is an other way to ignore the mass by enabling "Acceleration"

mesh->AddForce(FVector::RightVector * 1000,NAME_None, true);

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hi Thomas, I have a similar problem, I want to set velocity to my character, I have tried Mesh->SetLinearVelocity() and Mesh->AddForce(), I have followed your code, but still no motion, do you know why?

more ▼

answered Mar 09 '17 at 03:05 AM

avatar image

1 3 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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