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