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 set Linear and Rotation Velocities

Hi,

I'm looking to force the value of linear velocity and rotation velocity of an actor with physic. I want to do it in C++, but the only informations I get is for Blueprint :/ ...

Do you know if a setter and a getter existe for this in C++ ?

PS : I know there are AddForce and AddImpule, but that's not what I'm looking for.

Thank you !

Product Version: UE 4.16
Tags:
more ▼

asked Jun 11 '17 at 11:59 AM in C++ Programming

avatar image

Herobrine20XX
5 4 4 7

avatar image c4tnt Jun 11 '17 at 01:39 PM

Hi. If you have an idea how to do what you want on Blueprints you can just found a UPROPERTY \ UFUNCTION you used in blueprint and call it from c++. Most blueprint nodes is just an exposed UFUNCTIONS and you can use built-in VS search to found them. It can be tricky to identify a name of the function you need, but usually it is a node name with removed spaces ( Add Force node is AddForce function )

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

2 answers: sort voted first

UPrimitiveComponent::AddForce and UPrimitiveComponent::AddTorque are probably what you want. The last parameter of these functions, bAccelChange, will make it affect velocity directly rather than acting like a physical force.

If you really need more advanced stuff, use GetBodyInstance() to return the primitive component's FBodyInstance. Be aware, however, that UPrimitiveComponent and FBodyInstances aren't 1:1 - multiple UPrimitiveComponents may share a single FBodyInstance if they've been welded together by the physics engine.

The FBodyInstance directly exposes more stuff, notably SetAngularVelocity() and SetLinearVelocity(), but under the hood they pretty much identical to AddForce and AddTorque IIRC. It's just a different way of calling them with different parameters which ultimately do the same thing.

more ▼

answered Jun 12 '17 at 10:04 PM

avatar image

Teiwaz
639 27 29 57

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

Thank you very much ! I took a look at the last argument of UPrimitiveComponent::AddImpulse, and I didn't know it !

The problem is that I use UPrimitiveComponent::AddImpulseAtLocation and the last argument is not the same...

I think, I will take a look at UPrimitiveComponent::GetBodyInstance with FBodyInstance::SetAngularVelocity and FBodyInstance::SetLinearVelocity.

For the "at location" part, I'll use basic physics : https://www.youtube.com/watch?v=jM-R7Rk7Wuk

Hope the physics engine don't go crazy about it :D !

more ▼

answered Jun 13 '17 at 06:17 PM

avatar image

Herobrine20XX
5 4 4 7

(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