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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

C++ Equivalent to "Set Velocity" node in Floating Pawn Movement [SOLVED]

So, I cannot find the function/variable that works like the "Set Velocity" node in Blueprint. This node was extremely useful to completely change my floating pawns velocity on the fly without using any movement inputs. Is there an equivalent function that I am completely missing? I've scrawled through the source code going all the way from the floating pawn source code to Aactor, and I can't find anything like that dang node. It seems so simple, but I just can't find what I need to do.

This node: https://blueprintue.com/blueprint/k4smj_dh/

Product Version: UE 4.20
Tags:
more ▼

asked Jan 16 '19 at 05:18 AM in C++ Programming

avatar image

Aaronmac
3 1 2

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

2 answers: sort voted first

How about a different answer?

I just now got a chance to see your blueprint graph preview, and was reminded that (duh) you're dealing with a UFloatingPawnMovement component.

In that case, how about just setting the velocity directly on the movement component? Like so:

 FVector NewVelocity;   // whatever you want your actor's new velocity to be
 AActor* MyActor;
 [...]   // some code to get a pointer to the actor whose velocity you want to change
 if (MyActor != nullptr)
 {
     UMovementComponent* MovementComponent = Cast<UMovementComponent>(MyActor->GetComponentByClass(UFloatingPawnMovement::StaticClass()));
     if (MovementComponent != nullptr)
     {
         MovementComponent->Velocity = NewVelocity;
     }
 }

Hopefully this does the trick!

more ▼

answered Jan 17 '19 at 01:46 AM

avatar image

the_batch
1.2k 4 5 8

avatar image Aaronmac Jan 17 '19 at 04:17 AM

This functions perfectly! Visual Studio throws a typical "member is inaccessible" error/highlight which is annoying, but it compiles fine and works perfectly. You also taught me a valuable concept in casting/pointing to a parent class for specific things as well. Thank you!

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

You have a couple of options, but perhaps the best is UPrimitiveComponent::SetAllPhysicsLinearVelocity. With that, you should just need your actor's root component, which is the component you'll call this function on. For example:

 FVector NewVelocity;   // whatever you want your actor's new velocity to be
 AActor* MyActor;
 [...]   // some code to get a pointer to the actor whose velocity you want to change
 if (MyActor != nullptr)
 {
     USceneComponent* Component = MyActor->GetRootComponent();
     if (Component != nullptr)
     {
         Component->SetAllPhysicsLinearVelocity(NewVelocity, false);
     }
 }

If you want to see all of your options for manipulating physics velocities for an actor in C++, check out the API page for UPrimitiveComponent.

more ▼

answered Jan 16 '19 at 07:53 PM

avatar image

the_batch
1.2k 4 5 8

avatar image Aaronmac Jan 16 '19 at 08:38 PM

I'll try this when I get home from work! Thank you!

avatar image Aaronmac Jan 16 '19 at 11:36 PM

This unfortunately didn't work. My root component is a USphereComponent, and is not meant to be simulating physics. I need something that works in a kinematic space, not the physics space. I should be able to figure something out! Even if I have to pass a variable off into Blueprint in order to use that node, it should work. Not optimal, but if I have to resort to it I will!

(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