Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Arena War
      2. After Hours
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA Next

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  

Apply Forces and Momentums to Entity/Object

Recommended Posts


I recently looked at the existing documentations and descriptions about these natives: (15.05.17)



// 0x18FF00FC7EFF559E 0x28924E98



// 0xC5F68BE9613E2D18 0xC1C0855A



There are some mistakes and the descriptions are confusing.

As far as I know this is right:

APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS(Entity entity, int forceFlags, float x, float y, float z, BOOL p5, BOOL isDirectionRel, BOOL isAmountRel, BOOL p8)
{ invoke<Void>(0x18FF00FC7EFF559E, entity, forceType, x, y, z, p5, isDirectionRel, isAmountRel, p8); }

APPLY_FORCE_TO_ENTITY(Entity entity, int forceFlags, float x, float y, float z, float offsetX, float offsetY, float offsetZ, int boneIndex, BOOL isDirectionRel, BOOL ignoreUpVec, BOOL isAmountRel, BOOL p12, BOOL p13)
{ invoke<Void>(0xC5F68BE9613E2D18, entity, forceFlags, x, y, z, offsetX, offsetY, offsetZ, boneIndex, isDirectionRel, ignoreUpVec, isAmountRel, p12, p13); }

the only "documentation" about this is from ScriptHookVDotNet
public enum ForceType

Imo it doesn't make any sense because these are bitflags.
Only the three lowest bits work, if higher bits are set to 1 my script didn't apply any forces.

First bit (lowest): Strong force Flag, seems to be a simple multiplier
Second bit: Unkown Flag (Didn't see a difference, but didn't stop working compared to higher bits)
Third bit: Momentum Flag=1 (the vector (x,y,z) is a momentum and not a force anymore)


offsetX, offsetY, offsetZ
These parameters are frequently found as xRot, yRot, zRot but are the offset of the force attack point.
For solid bodies there's no such thing like a attack point for momentums (called free momentum in german) so the offset is needless then.

isDirectionRel determines if the direction of the force vector is in global/world coordinates or in relative coordinates (e.g. the thrust from a jet engine is body fixed)

ignoreUpVec could someone explain this one for me, any code I've found sets this TRUE-

isAmountRel enables mass multiplier

In other words if this is set to FALSE, the force has a constant value (Newton) for all objects. A heavy object will accelerate slower than a light object.

If this is set to TRUE the force will be multiplied with the mass, so as a result the acceleration is a constant value for all objects.

p8 (Center of mass function) whenever I set this to TRUE my scripts stops running. -> Always false (at least for me)

p5 (Center of mass function) didn't see a difference if set to TRUE or FALSE, (didn't check for complex entity like peds with mutliple bones)

p12 is always set to FALSE, didn't test it.

p13 is always set to TRUE, didn't test it as well.


Please share your knowledge! (Imo these are very important methods for many modders)

Edited by LeFix

Share this post

Link to post
Share on other sites

Momentums behave super weird, I don't understand what's happening behind the scences.

Applying an arbitrary momentum to an object often leads to a pendulum-like motion. (Rotation gets faster then stops and spins backwards again and so on)

This occurs with global and local momentum (isDirRel setting), but maybe my description is (partly) wrong for momentums or there's another relevant parameter.

I guess I have to implement them as pairs of opposite forces.



Meanwhile I implemented the workaround and it works absolutely fine for body fixed momentums.

void ENTITY::APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS(Entity entity, Vektor3D force, bool isDirRel, bool isStrong, bool isMassRel){	int forceFlags = 0u;	if (isStrong) forceFlags |= (1u << 0); //Set first bit	//LAST BOOL HAS TO BE FALSE (SCRIPT STOPS RUNNING)	ENTITY::APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS(entity, forceFlags, force.x, force.y, force.z, FALSE, isDirRel, isMassRel, FALSE);}
void ENTITY::APPLY_FORCE_TO_ENTITY(Entity entity, Vektor3D force, Vektor3D offset, int boneIndex, bool isDirRel, bool isStrong, bool isMassRel){	int forceFlags = 0u;	if (isStrong) forceFlags |= (1u << 0); //Set first bit	ENTITY::APPLY_FORCE_TO_ENTITY(entity, forceFlags, force.x, force.y, force.z, offset.x, offset.y, offset.z, boneIndex, isDirRel, TRUE, isMassRel, FALSE, TRUE);}
void ENTITY::APPLY_MOMENTUM_TO_ENTITY(Entity entity, Vektor3D momentum, int boneIndex, bool isStrong, bool isMassRel){	//This method has no isDirRel setting!	//For the workaround I would have to pass or read the objects rotation to calculate the global force pair.	//And I don't need global momentums for my mod...	float momSqr = momentum.getNormSquared();	//Why is a zero momentum vector stopping body rotation?	//Following code produces zero vectors (force and offset) which shouldn't stop object roation.	if (momSqr < 0.0001f*0.0001f) return; //Workaround: Don't apply forces at all when momentum is near zero.	// FIRST: get an arbitrary perpendicular vector to momentum	Vektor3D offset = Vektor3D(0.0f, momentum.z, -momentum.y); //Crossproduct with (1/0/0)	//Check if (1/0/0) was a good choice (almost parallel is bad)        //0.7f (~1/sqrt(2)) close to zero has probably a better performance	if (offset.getNormSquared() < 0.7f*momSqr) {		offset = Vektor3D(-momentum.z, 0.0f, momentum.x); //Crossproduct with (0/1/0) has to be better than (1/0/0)	}	offset.normalize();	// SECOND: calculate the force vector(s)	Vektor3D force = momentum.cross(offset);	// THIRD: force flags, momentums behave strange can't properly use them yet	int forceFlags = 0u;	if (isStrong) forceFlags |= (1u << 0); //Set first bit	//forceFlags |= (1u << 2); //Set third bit	// FOURTH: Apply Forces which are physically the same as the desired momentum	ENTITY::APPLY_FORCE_TO_ENTITY(entity, force*(+1.0f), offset*(+0.5f), boneIndex, true, isStrong, isMassRel);	ENTITY::APPLY_FORCE_TO_ENTITY(entity, force*(-1.0f), offset*(-0.5f), boneIndex, true, isStrong, isMassRel);	//ENTITY::APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS(entity, forceFlags, momentum.x, momentum.y, momentum.z, FALSE, isDirRel, isMassRel, FALSE); //y u no work}
Edited by LeFix

Share this post

Link to post
Share on other sites

I checked the isStrong force flag and so far it looks like it its a simple factor which is applied. -> 100

Two identical objects should have the same acceleration wih these settings:

Object A -> force:1, isStrong:false

Object B -> force:0.01, isStrong: true



The differences are really small and they vary during multiple runs. (Randomly)

When I do the same with two identical objects and apply identical forces (isStrong setting as well) there are some small velocity differences too(!)

(Something like floating point errors I assume)


I also checked the collision behavior by applying opposite forces to two identical objects which push them against each other in air.

(One force isStrong=true multiplied with 0.01f, the other isStrong=false)

Even then there's no real difference, they just stay at the same spot)


Thought the force calculations might be in a specific order so two different force types interact in a specific way, no they don't.


Unit of the applied force?

I already mentioned (other thread?) that objects (with no drag) will fall with an acceleration of 10m/s^2 (gravity setting 1.0=default)

This is 10 Newtons/Kilogram

First i thought applying a force (x=0;y=0;z=-10; isStrong=false, isMassRel=true) would accelerate any object the same way like the inbuilt gravity does, but this only accelerates them with 5m/s^2!

So the vector used for applying a force to an entity has the unit 0.5Newtons(/Kilograms if isMassRel=true);

Edited by LeFix

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • 1 User Currently Viewing
    0 Members, 0 Anonymous, 1 Guest


Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.