Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

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

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

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

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

    2. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

Apply Forces and Momentums to Entity/Object


LeFix
 Share

Recommended Posts

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

http://www.dev-c.com/nativedb/func/info/18ff00fc7eff559e

known as APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS

// 0x18FF00FC7EFF559E 0x28924E98

http://www.dev-c.com/nativedb/func/info/c5f68be9613e2d18

known as APPLY_FORCE_TO_ENTITY

// 0xC5F68BE9613E2D18 0xC1C0855A

https://github.com/crosire/scripthookvdotnet/blob/dev_v3/source/scripting/Entity.cs

(ScriptHookVDotNet)

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); }

forceFlags
the only "documentation" about this is from ScriptHookVDotNet
public enum ForceType
{
MinForce,
MaxForceRot,
MinForce2,
MaxForceRot2,
ForceNoRot,
ForceRotPlusForce
}


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
Link to comment
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.

 

Edit:

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
Link to comment
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

 

Edit:

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
  • Like 3
Link to comment
Share on other sites

  • 3 years later...

Sorry to revive an old post but doing some research into applying forces and can verify for you that ignoreUpVec, without the words to explain it itself, if you apply a force on the X/Y axis of an entity, and you have that set FALSE, once the entity turns "upsidedown" the force will aplly "backwards" and flip them back over the way they came, rather than continue the force to complete the original flip.

Link to comment
Share on other sites

  • 1 year later...
YouDontKnowMyName

Hi. I know It Is an old post but I have a question.

When I use entity force the peds and vehicles fly and the other players stay there. I want other players fly too,  How can I fix this ? 

Edited by YouDontKnowMyName
Link to comment
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
 Share

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

×
×
  • Create New...

Important Information

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