Skip to content

Commit 6198ca2

Browse files
document 2 force natives (#1203)
* document 2 force natives * add back links * add back links * remove link * Apply suggestions from code review --------- Co-authored-by: Dillon Skaggs <dillskaggs@gmail.com>
1 parent eab3379 commit 6198ca2

File tree

2 files changed

+48
-62
lines changed

2 files changed

+48
-62
lines changed

ENTITY/ApplyForceToEntity.md

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,61 @@ ns: ENTITY
55

66
```c
77
// 0xC5F68BE9613E2D18 0xC1C0855A
8-
void APPLY_FORCE_TO_ENTITY(Entity entity, int forceType, float x, float y, float z, float offX, float offY, float offZ, int boneIndex, BOOL isDirectionRel, BOOL ignoreUpVec, BOOL isForceRel, BOOL p12, BOOL p13);
8+
void APPLY_FORCE_TO_ENTITY(Entity entity, int forceType, float x, float y, float z, float offX, float offY, float offZ, int nComponent, BOOL bLocalForce, BOOL bLocalOffset, BOOL bScaleByMass, BOOL bPlayAudio, BOOL bScaleByTimeWarp);
99
```
1010
11-
Applies a force to the specified entity.
1211
1312
```c
14-
enum eForceType
15-
{
16-
MinForce = 0,
17-
MaxForceRot = 1,
18-
MinForce2 = 2,
19-
MaxForceRot2 = 3,
20-
ForceNoRot = 4,
21-
ForceRotPlusForce = 5
13+
enum eApplyForceTypes {
14+
APPLY_TYPE_FORCE = 0,
15+
APPLY_TYPE_IMPULSE = 1,
16+
APPLY_TYPE_EXTERNAL_FORCE = 2,
17+
APPLY_TYPE_EXTERNAL_IMPULSE = 3,
18+
APPLY_TYPE_TORQUE = 4,
19+
APPLY_TYPE_ANGULAR_IMPULSE = 5
2220
}
2321
```
2422

25-
Research/documentation on the gtaforums can be found [here](https://gtaforums.com/topic/885669-precisely-define-object-physics/) and [here](https://gtaforums.com/topic/887362-apply-forces-and-momentums-to-entityobject/).
26-
27-
2823
## Parameters
29-
* **entity**: The entity you want to apply a force on
30-
* **forceType**: Refer to `eForceType`
31-
* **x**: Force amount (X)
32-
* **y**: Force amount (Y)
33-
* **z**: Force amount (Z)
34-
* **offX**: Rotation/offset force (X)
35-
* **offY**: Rotation/offset force (Y)
36-
* **offZ**: Rotation/offset force (Z)
37-
* **boneIndex**: (Often 0) Entity bone index
38-
* **isDirectionRel**: (Usually false) Vector defined in local (body-fixed) coordinate frame
39-
* **ignoreUpVec**: (Usually true)
40-
* **isForceRel**: (Usually true) When true, force gets multiplied with the objects mass and different objects will have the same acceleration
41-
* **p12**: (Usually false)
42-
* **p13**: (Usually true)
43-
24+
* **entity**: The entity handle
25+
* **forceType**: The force type
26+
* **x**: The x component of the force to apply
27+
* **y**: The y component of the force to apply
28+
* **z**: The z component of the force to apply
29+
* **offX**: Offset from center of entity (X)
30+
* **offY**: Offset from center of entity (Y)
31+
* **offZ**: Offset from center of entity (Z)
32+
* **nComponent**: Component of the entity to apply the force too. Only matters for breakable or articulated (ragdoll) physics. 0 means the root or parent component
33+
* **bLocalForce**: Specifies whether the force vector passed in is in local or world coordinates. `true` means the force will get automatically transformed into world space before being applied
34+
* **bLocalOffset**: Specifies whether the offset passed in is in local or world coordinates
35+
* **bScaleByMass**: Specifies whether to scale the force by mass
36+
* **bPlayAudio**: Specifies whether to play audio events related to the force being applied. The audio will depend on the entity type. Currently vehicles are the only entity types supported, and will play a suspension squeal depending on the magnitude of the force
37+
* **bScaleByTimeWarp**: Specifies whether to scale the force by time warp. Default is `true`
4438

4539
## Examples
4640
```lua
47-
local forceTypes = {
48-
MinForce = 0,
49-
MaxForceRot = 1,
50-
MinForce2 = 2,
51-
MaxForceRot2 = 3,
52-
ForceNoRot = 4,
53-
ForceRotPlusForce = 5
54-
}
55-
5641
local entity = PlayerPedId()
57-
local forceType = forceTypes.MaxForceRot2
42+
local forceType = 2
5843
-- sends the entity straight up into the sky:
5944
local direction = vector3(0.0, 0.0, 15.0)
60-
local rotation = vector3(0.0, 0.0, 0.0)
61-
local boneIndex = 0
62-
local isDirectionRel = false
63-
local ignoreUpVec = true
64-
local isForceRel = true
65-
local p12 = false
66-
local p13 = true
45+
local offset = vector3(0.0, 0.0, 0.0)
46+
local component = 0
47+
local localForce = false
48+
local localOffset = true
49+
local scaleByMass = true
50+
local playAudio = false
51+
local scaleByTimeWarp = true
6752

6853
ApplyForceToEntity(
6954
entity,
7055
forceType,
7156
direction,
72-
rotation,
57+
offset,
7358
boneIndex,
74-
isDirectionRel,
75-
ignoreUpVec,
76-
isForceRel,
77-
p12,
78-
p13
59+
localForce,
60+
localOffset,
61+
scaleByMass,
62+
playAudio,
63+
scaleByTimeWarp
7964
)
8065
```

ENTITY/ApplyForceToEntityCenterOfMass.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ ns: ENTITY
55

66
```c
77
// 0x18FF00FC7EFF559E 0x28924E98
8-
void APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS(Entity entity, int forceType, float x, float y, float z, BOOL p5, BOOL isDirectionRel, BOOL isForceRel, BOOL p8);
8+
void APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS(Entity entity, int forceType, float x, float y, float z, cs_type(BOOL) int nComponent, BOOL bLocalForce, BOOL bScaleByMass, BOOL bApplyToChildren);
99
```
1010
11-
## Parameters
12-
* **entity**:
13-
* **forceType**: Refer to [APPLY_FORCE_TO_ENTITY](#_0xC5F68BE9613E2D18)
14-
* **x**:
15-
* **y**:
16-
* **z**:
17-
* **p5**:
18-
* **isDirectionRel**:
19-
* **isForceRel**:
20-
* **p8**:
11+
Apply a force to an entities center of mass.
2112
13+
## Parameters
14+
* **entity**: The entity handle
15+
* **forceType**: The force type, see [`APPLY_FORCE_TO_ENTITY`](#_0xC5F68BE9613E2D18)
16+
* **x**: The x component of the force to apply
17+
* **y**: The y component of the force to apply
18+
* **z**: The z component of the force to apply
19+
* **nComponent**: Component of the entity to apply the force too. Only matters for breakable or articulated (ragdoll) physics. 0 means the root or parent component
20+
* **bLocalForce**: Specifies whether the force vector passed in is in local or world coordinates. `true` means the force will get automatically transformed into world space before being applied
21+
* **bScaleByMass**: Specifies whether to scale the force by mass
22+
* **bApplyToChildren**: Default `false`. If the force should be applied to any attached children

0 commit comments

Comments
 (0)