How to set Linear and Rotation Velocities
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 !
asked Jun 11 '17 at 11:59 AM in C++ Programming
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.
answered Jun 12 '17 at 10:04 PM
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...
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 !
answered Jun 13 '17 at 06:17 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here