[Coding] How 2 Jet physics basic

Making or wanting help making your own asset? Check in here
Post Reply
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

[Coding] How 2 Jet physics basic

Post by rPoXoTauJIo »

As some of you may noticed, 1.4 came up with updated physics on jets, and i through that it would be good to explain some stuff if someone want's to experiment aswell and think he can do better.

Tools you'll need:
  • PR 1.4x
  • Winrar\etc for working with archives.
  • Notepad(++) for coding.
1. Some theory first.

Bf2 modding is all about modifying files with code that engine parsing into objects templates to be created&simulated later in game. As a bf1942 legacy, all objects still being initialized through .con files, but difference in bf2 is that .tweak files used to assign objects parameters like mass, torque, wings lift, rotation etc. You can edit them with your favorite vim or other editor(i prefer Notepad++ but heard mats using pycharm)
Small note about locating files:
Jets configs usually placed in /objects/vehicles/air/<jetname>/<jetname>.tweak
Directory /objects/ is always mounted in <root_game>/mods/<mod_name>/ folder, regardless if it's a actual folder(bf2editor work only with unpacked folder), or it's mounted zipfile(game works only with archives). Archives are being mounted through client or serverarchives.con in mod root.

To change something in-game, you need to change content in needed archive, as for pr jets it's in <mod_root>/content/objects_vehicles_server.zip

MAKE BACKUPS FIRST OR YOU WON'T BE ABLE PLAY ONLINE

2. Editing parameters

All objects in engine are being created from templates which we describe in those files.
Coding objects in bf2 are done via selecting objects and tweaking them.

Code: Select all

ObjectTemplate.create Wing ru_jet_su27_Wing_Front
ObjectTemplate.setWingLift 0.3

Code: Select all

ObjectTemplate.activeSafe RotationalBundle ru_jet_su27_AirBrake
ObjectTemplate.setMaxRotation 0/50/0
What you need to look is for lines ObjectTemplate.create or ObjectTemplate.activeSafe(Wing or RotationalBundle is just a types of object) in this case they mean that we either create object, or we select already existing object. Note that we operate in global scope here, you for sure can create some wing in one file, and create another wing in other, and have them all added to vehicle template in third file.
After selecting object we can tweak it. In first case for example i'm modifying wing lift, and for second object i'm tweaking it's maximum rotation.
Most of commands are self-explanatory, but if you have bfeditor downloaded, some commands are explained in <game_root>/bfeditor/help/ folder.

So tl;dr if you see some tweak command that's mean it's tweaking object that's been created or activated somewhere's higher in code.

3. Main body parameters

Speaking about jets, we're specifically interested in this parts of code:
In main PCO(PlayerControlObject) there's few values that affect plane physics as a whole object.

Code: Select all

ObjectTemplate.drag 1
ObjectTemplate.gravityModifier 1
  • .drag affecting how much "air" resist when flying. The more value, the less max speed plane will be able to achieve.
    Side effect is that drag affecting vertical movement aswell. If remove wings, increasing-decreasing value will affect how jet will drift aswell. Ideally this should be kept at 0.1 for jets.
  • .gravityModifier affecting how stronk gravity will be. Keep in mind that if you will change it, you'll need to tweak landing gear aswell.
But as jet isn't single piece object being combined from different objects somehow we need to tell template to load them:
ObjectTemplate.addTemplate ru_jet_su27_EngineMain
ObjectTemplate.setPosition 0.0/0.0/-10
ObjectTemplate.addTemplate ru_jet_su27_RudderYaw
ObjectTemplate.setPosition 0/0.0/-7.0
ObjectTemplate.setRotation 0/-30.0/-90.0000
Basically just telling to use object created somewhere else, and setting up it's position and rotation.
In bf2 engine x/y/z position is floating point values(16bit precision iirc), where x for left(negative)&right(positive), y for top&bottom, z for front&back. Same goes for yaw/pitch/roll.


4. Engine

Code: Select all

ObjectTemplate.create Engine ru_jet_su27_EngineMain
ObjectTemplate.setMinRotation 0/0/0
ObjectTemplate.setMaxRotation 0/0/2000
ObjectTemplate.setMaxSpeed 0/0/1000
ObjectTemplate.setAcceleration 0/0/100

Code: Select all

ObjectTemplate.setTorque 150
ObjectTemplate.setDifferential 900
First part of code is responsible for start-up and engine responsiveness, imagine it as engine having 2000 deg to heat, and it's heating with max speed of 1000, and acceleration of 100. Other than that is just to play with values.
Second part is torque and differential and it responsible for jet thrust and max speed. While torque directly responsible for torque, differential affect max speed in weird way, but generally increasing it increasing max speed aswell.

The primary issue with engines in bf2 is that we can't have inertial. So basically only force that keep pushing jet through the air is it's engine.

5. Wings

Code: Select all

ObjectTemplate.create Wing ru_jet_su27_Wing_Front
ObjectTemplate.setWingLift 0.3
Wings is wings :P They have lift that will appear with speed increase. But they still have few surprises that may come up with.
First of all - they do not automatically lift you in air. Winglift value describing only how much resistance wing will cause when moving through air. That's something we've used in our Mk82 retarded bombs in the Falklands update.
As for controlling jet in air, we just have a set of wings that can rotate around so jet can yaw, pitch, roll.

Code: Select all

ObjectTemplate.create Wing ru_jet_su27_Winglet
ObjectTemplate.setMinRotation 0/-15/0
ObjectTemplate.setMaxRotation 0/20/0
ObjectTemplate.setMaxSpeed 0/300/0
ObjectTemplate.setAcceleration 0/-150/0
ObjectTemplate.setInputToPitch PIPitch

ObjectTemplate.setWingLift 0.2
ObjectTemplate.setFlapLift 0.15
First part describing how much(in degrees) wing can rotate, with which speed, and how fast it will accelerate to rotate. Input method is PIPitch which is mouse up or arrow up or whatever you set in game settings.

Second part is tricky one. While winglift working all the time, flaplift activates only when you rotate wing, and being added to winglift.


6. PR 1.4 jets setup


Previously, in pre-1.4 pr versions jets had wings mixed with rotational bundles and those being control surfaces at different coordinates on each jet. For 1.4.x setup i decided to split up rotational bundles visual wings and real physical wings. This allows me to have nicer numbers :) and what's more important, have physical wings setups independently from jet visual body.
Starting from scratch, i quickly(no) found cheapest(in terms of networkables) model possible is being a 3-point setup with back wing allowed to rotate for pitch controls. Later by center point were replaced by pair of roll controls on sides, and added vertical wing + rudder for yaw control.

Using su27 as example:
Image
Image

Modifying values at those points will change behavior of jet as you need, all you need for now just try and mistake. Do not hesitate to ask questions as otherwise i wasted ~2 years on experiments with physics :D
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
RazzorRost
Posts: 7
Joined: 2017-02-16 14:20

Re: [Coding] How 2 Jet physics basic

Post by RazzorRost »

Interesting!! I'll try to change basic physics on vanila air_j10 for my custom mod in standart bf2
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

Re: [Coding] How 2 Jet physics basic

Post by rPoXoTauJIo »

As for vbf2, you gotta keep in mind 2 points :)
1. All rotated parts being wings aswell, so instead of creating them from .tweak like i did in pr, they're being created in .con file, and then tweaked(through activeSafe) in .tweak file.

Code: Select all

ObjectTemplate.activeSafe Wing AIR_J10_RWinglet
ObjectTemplate.modifiedByUser ljo
ObjectTemplate.setNetworkableInfo BasicInfo
ObjectTemplate.floaterMod 0
ObjectTemplate.hasMobilePhysics 1
ObjectTemplate.hasCollisionPhysics 1
ObjectTemplate.physicsType Mesh
rem -------------------------------------
ObjectTemplate.addTemplate S_AIR_J10_RWinglet_RotationRpm
rem -------------------------------------
ObjectTemplate.setMinRotation 0/-4/0
ObjectTemplate.setMaxRotation 0/4/0
ObjectTemplate.setMaxSpeed 0/300/0
ObjectTemplate.setAcceleration 0/75/0
ObjectTemplate.setInputToPitch PIPitch
ObjectTemplate.setAutomaticReset 1
ObjectTemplate.rememberExcessInput 1
ObjectTemplate.setPitchOffset 1.8
ObjectTemplate.setPositionOffset 1/-0.2565/0
ObjectTemplate.setWingLift 0
ObjectTemplate.setFlapLift 1.2

ObjectTemplate.activeSafe Sound S_AIR_J10_RWinglet_RotationRpm
ObjectTemplate.modifiedByUser ljo
2. Bf2 store their templates in both client and server for some reason. So you gotta repack both objects_client.zip and objects_server.zip.
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
RazzorRost
Posts: 7
Joined: 2017-02-16 14:20

Re: [Coding] How 2 Jet physics basic

Post by RazzorRost »

So if i have bf3 model of F18 super hornet(from chinees modding comunity) with standart usair_f18.tweak, i must go to .con and .tweak to make the plane more maneuverable + adding this code like -- ObjectTemplate.mass 18000-- make me feeling of his mass in flight? Also i want to make the A-10/Q5/Su-25TM more heavy in flight, but more powerfull!
Last edited by RazzorRost on 2017-02-16 21:34, edited 1 time in total.
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

Re: [Coding] How 2 Jet physics basic

Post by rPoXoTauJIo »

ObjectTemplate.mass doesn't add anything for physics but used for collisions calculations, object with larger mass will push object with lesser mass.
General approach for making jet "heavier" is increasing gravityModifier, and decreasing wings lifts.
As for example vbf2 jets usually have wing\flap lifts around 1, while new pr values around 0.2-0.5 making them less railway-like.
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
RazzorRost
Posts: 7
Joined: 2017-02-16 14:20

Re: [Coding] How 2 Jet physics basic

Post by RazzorRost »

also i used this post to modify helicopters flight
https://www.realitymod.com/forum/f388-pr-bf2-community-modding/141387-chopper-flight-models.html
Thank you!!!
Last edited by rPoXoTauJIo on 2017-02-17 18:38, edited 1 time in total.
Reason: Fixed link
RazzorRost
Posts: 7
Joined: 2017-02-16 14:20

Re: [Coding] How 2 Jet physics basic

Post by RazzorRost »

Also i want to ask how this code- physics.airdensityzeroatheight - influence on aircraft\helicopter and how to modify this code for proper flight?
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

Re: [Coding] How 2 Jet physics basic

Post by rPoXoTauJIo »

This one being used for raising maximum flight height, f.e. vanilla bf2 has value of 1000 and their jets losing control ~800-900m, so do in PR this value set to 10000 and jets losing controls ~ 8000-9000m.
This value hardcoded to 1000 by default, and map-based - therefor PR change that through custom init system:
Map calling init.con->mod_root/factions/factions_init.con
This file is being mounted in content/factions_server.zip.
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
RazzorRost
Posts: 7
Joined: 2017-02-16 14:20

Re: [Coding] How 2 Jet physics basic

Post by RazzorRost »

Truly!!Bots now flying on jest over my head, instead in front of barrel of my gun!!!
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

Re: [Coding] How 2 Jet physics basic

Post by rPoXoTauJIo »

Through it would be good to share tool i'm using to tweak jets on live game server instead of modify-load-test-unload sequence.
Require some understanding how to work with python and bf2 tweaks. Dont mind dirt code, no time to fix it :p
https://github.com/rPoXoTauJIo/objmodv2
How to use:
1. Import shit so it launch without error.
2. Setup queries in constants.DEFAULT_QUERIES, i've included some examples.
3. Type '!obj reload' in game chat, hit ~ button to check console, there's should be a bunch of debug.

Few notes:
Not everything works - specifically, this tool wont affect visual parts, so f.e. if you will try to change rotation on RotationalBundle which has geometry it wont have any effect.

Example(changed deviation here):
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
RazzorRost
Posts: 7
Joined: 2017-02-16 14:20

Re: [Coding] How 2 Jet physics basic

Post by RazzorRost »

Glad to see more new features For BF2 modding, especially coding!!
Post Reply

Return to “PR:BF2 Community Modding”