x

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"

How To Add a local force

I am trying to make a small plane fly. I already have a pawn, applied physics and now it falls to the ground and collides. Now I set up PlayerInput that would let the player apply a force by the press of a button. The problem is, when I press play and steer the plane in an upwards direction (by using AddTorque) the plane still gets pushed In a horizontal direction. What can I do to fix this and how do I apply the force correctly and locally? I tried using AddForceAtLocation, but then the pawn just started spinning uncontrollably.

This is my code:

 void AMyPawnOne::SetupPlayerInputComponent(class UInputComponent* InputComponent)
 {
     Super::SetupPlayerInputComponent(InputComponent);
 
 
     InputComponent->BindAxis("PlanePitch", this, &AMyPawnOne::PlanePitch);
     InputComponent->BindAxis("PlaneThrust", this, &AMyPawnOne::PlaneThrust);
 }
 
 void AMyPawnOne::PlanePitch(float AxisValue)
 {
     PlaneMesh->AddTorque(FVector(0.0f, -5000.0f, 0.0f)*AxisValue);
 }
 
 void AMyPawnOne::PlaneThrust(float AxisValue)
 {
     PlaneMesh->AddForce(FVector(5000.0f, 0.0f, 0.0f)*AxisValue);
 }
 
Product Version: UE 4.7
Tags:
more ▼

asked Jul 20 '15 at 01:00 PM in C++ Programming

avatar image

Nemooo
6 2 3 4

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

1 answer: sort voted first

This is a little old, so you may have figured it out, but I think you need to use the GetActorForwardVector() and multiply it by the thrust, usually a float I guess, instead of setting the X component of the vector to 5000. I believe that makes it go in the X direction relative to the world.

 float thrust = 5000;
 
 void AMyPawnOne::PlaneThrust(float AxisValue)
  {
      PlaneMesh->AddForce(GetActorForwardVector() * thrust * AxisValue);
  }
more ▼

answered Nov 24 '15 at 07:11 PM

avatar image

Daiern
18 3 5 8

(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