Someone tried to fix this already, but it seems it caused a more severe problem than what was going to be fixed by this since it caused the cars to sink into the ground:
https://sourceforge.net/p/trigger-rally/patches/9/
To me it looks like a problem of a too high reference point of the vehicle files, but I actually don't know how gravity gets calculated in Trigger...
The latest commit for vehicle.cpp is 2012-05-24 jareiko.
http://sourceforge.net/p/trigger-rally/code/HEAD/tree/src/psim/
Farrer's source code was released on 2012-08-15 Farrer
http://sourceforge.net/p/trigger-rally/patches/9/
I check the source code at SourceForge
http://sourceforge.net/p/trigger-rally/code/HEAD/tree/src/psim/vehicle.cpp#l4
Farrer never merged the new patch "not_contacting_ground_patch.diff" into the source code "vehicle.cpp".
I suppose that you still use the source code "vehicle.cpp" released on 2012-05-24
NOT 2012-08-15
Which version of the source code "vehicle.cpp" you use in the racing game?
That's correct I never tried to use the patch since in the discussion of it the problem of the "diving" cars was confirmed. I would rather have moon like gravity than cars, that are partly hidden in the ground.
Further more I find the idea of a gravity odd if it is appied only when no wheel touches the ground since the reason for leaving the ground in the first place is not touched by this. I think gravity should be applied all the time. If that doesn't work properly, I see a problem with the proposed solution...
Before I revise the C++ code, I have three questions on the new patch:
Question #1:
Quote from Farrer's comment "Anyway, if the force was applied as a real gravity, affecting the car all the time (to do it, just comment the "if(noContactCount == 4)" at "src/psim/vehicle.cpp" patched file), the car will enter the ground, acting as if it is of water and the car a boat, which is yet less desirable for a car game (maybe an anphibyous game? =^D )"
(1) the new patch is created for the less-gravity on the moon.
(2) we need to comment out "if(noContactCount == 4)" to adapt to the real-gravity on the earth.
This means that "vehicle.cpp needs to detect which kind of map the player chooses?"
Question #2:
I can NOT find any moon map from the latest version of Trigger-Rally game.
Would you please let me know which map in the following link is a moon map?
https://sourceforge.net/p/trigger-rally/code/HEAD/tree/data/maps/
Question #3:
qubodup provides the Videos of driving straight on Smallswirl:
without patch http://youtu.be/Hh82utIaLbg
with patch http://youtu.be/O8lrpxeV9MA
I can NOT quite understand qubodup's question: "Are there different physics depending on whether the car has contact to the ground or not?"
https://sourceforge.net/p/trigger-rally/patches/9/
What does different physics mean?
Hi Winston,
Question 1 and 2:
I think your first question derives from an unfortunate badly expressed thought. Even if there is a map called "Lunar" or "Far far away" in the event "Trigger Cup" which seems to refer to the moon, this is just ment optically. As far as I know nobody deliberately wanted to have moon-like gravity. This is just how the original game physics feel like.
Farrer tried to fix the annoying problem of unrealisticly high and wide flying cars by adding gravity to it. But since this gravity caused the cars to enter the ground he worked around it by applying the gravity factor only when no wheel touches the ground. In my opinion this is not satisfactory because it doesn't create more realistic game physics. Therefore I never considered this patch as a solution.
The link you are referring to are not the original single race maps done by the creators of Trigger Rally, but later additions from various people. The moon like map was done by the original creators as part of the first event: "Trigger Cup" and therefore can't be found in this folder.
Question 3:
Oubodup refers to the fact that Farrer applied the gravity facor only when no wheel is touching the ground. Farrer did that for a good reason since he ended up with cars sitting in the ground instead of driving over the ground when he applied the gravitational force permanently. Farrer confirmed that his patch was just a quick and dirty way of getting rid of flying cars.
In my opinion the gravitational force might be a little to strong, but would work fine if you remove the limitation of it being applied only when no wheel is touching the ground and if you can fix the problem of the car sinking into the ground some other way.
My problem with the patch at the moment is the effect, that it is still very easy to loose contact to the ground with some wheels. Therefore the most annoying part of the moon like gravity is not resolved by it. The car is still behaving like a boat on wild water and it's hard to steer if half of the time only two wheels are on the ground.
I hope I could clarify some things here.
Last edit: Onsemeliot 2014-05-22
Today I just added 150 units to all vehicle weights and I was surprised to not face the problem of cars sinking into the ground. Vehcles now are not as likely to take off at every pump, but they are still light enough to make nice jumps.
I didn't expect all cars to have the same weight, but I didn't alter that. Originally the value was 1350. I adapted it to 1500 and I think it was an improvement.
Hi. I am trying to work on a solution to this problem, but I have some questions about it. As I see is more than a year that no one write something here.
What is the current state of the bug? The patch to have the gravity only when the wheels don't touch the ground has been committed? If not, how/where the gravity is computed? I examinated the file vehicle.cpp and other files in these days, and I found no explicit refer to gravity.
Maybe the answer to these questions has already been written, but I don't get english too well, and this is not clear to me.
Last edit: Emanuele Sorce 2017-01-24
No this patch hasn't been comitted because we think it wouldn't solve the main problem of the cars getting out of control very easily. At least I consider huge jumps as less of a problem than uncontrollable vehicles.
As far as I know Andrei tried to understand the physics code already but did have similar problems. He reported back that he didn't understand the involved mathematics. I get from this that the key here is propably mathematics and not the programming.
Sorry, that I can't be of more help. We even tried to ask Jasmine, the original programmer but unfortunately she didn't have time to help us understanding the calculations.
Without having a true understanding of the car handling problems, my intuition tells me that there are at least two problems to be fixed:
That's true. Eventually I'll have to make the (long overdue) effort to learn maths and physics.
The class
PRigidBodyapparently accumulates the forces on the vehicle while the classPSimapparently controls the gravity value (as a 3D vector).PRigidBodyPSimEDIT: fixed typo ("strings" -> "springs") and links (HEAD -> r851)
Last edit: Andrei 2017-01-25
Ok. I'll try to understand what the physic engine precisely does, document it and try to fix the issue.
Last edit: Emanuele Sorce 2017-01-25
As Andrei correctly says, the gravity is calculated in rigidbody.cpp, as a force applyed in the center of mass of the body(the car), I checked it and is calculated correctly. Is the line "linvel += (accum_force * mass_inv + sim.gravity) * delta;" (line number 114 or near there). sim.gravity is initialized correctly in game.cpp as vec3f(0.0, 0.0, -9.81). So the gravity issue is caused somewhere else, I'm looking for it.
Last edit: Emanuele Sorce 2017-01-25
Emanuele, I believe that there is no gravity problem and instead the problem could be how the wheels interact with the terrain.
When I last worked on this code it seemed to me that the wheel grip is not calculated depending on how much surface of the wheel is in contact with terrain. If this is true, then it means that a wheel barely touching the terrain at 45 degrees angle will still have full grip (which will lead to instability).
Another possible reason for instability is that the game applies aerodynamic downforce to the cars. At high speeds this is noticeable because the car's suspension gets shorter (as if the car gets heavy). If these downforce calculations are incorrect (or incomplete) then they will obviously lead to erratic handling if the car body loses the "correct" alignment during high speed.
As far as I have seen there is no evidence of any gravity issue, so you are right. This also mean that there is no moon-like gravity, but this feeling is a sum of various physic incorrect implementations, like the two you wrote below:
Last edit: Emanuele Sorce 2017-01-25
I'm obviously not an expert. But couldn't the problem be caused by the fact that gravity is calculated in the gravity center only?
Considering your original wish to add the more advanced wheels gyroscopes you might need to calculate gravity more fine-grained in order to reach a satisfying effect with such code. Or am I wrong there?
I have absolutely no idea how gravity should be calculated, but maybe it would be helpful to check how gravity is calculated in Torcs. As I understand it the physics engine there is rather realistic since it has been used for all kinds of simulation and science projects.
But despite the obvious issues with Trigger Rally's physics, in my personal view the drifting experience with Trigger Rally feels far superior to all other free software racing games I encountered so far. Stunt Rally feels like playing with toy cars and Torcs feels more like racing with trains on rails (when on the road) but totally suck when offroad. The great drifting was one of the key features luring me to the Trigger Rally in the first place. In my opinion this is unmatched in the free software field so far. So I wouldn't want to trade this drifting experience for a boring but correct behavior. If gaining a proper physical behavior would mean to lose this great drifting experience I would stick to the moon like gravity. I think the drifting is comparable to the Colin McRae gamne series which had great physics (at least in the past when I didn't avoid non-free programs).
I have thinked that too. But I checked the code carefully and seems not. This because the gravity is centered in the gravity center, and this should basically works, even if a more precise calculation could make the simulation a bit more realistic, but now what makes the driving experience buggy sometimes is not this. For example when the car touches the ground only with the two side wheels, what makes the car regain stability, is not the gravity itself, but the two wheels that touching the ground produce a force directed to the up; that cause a torque that makes the car roll. (Sorry again if my explainations are not so clear, but I don't sppeak english very well).
+1. I thinked to contribute to the developing of this program just recently, but it's much time that I play and enjoy trigger rally. I'm working to enhance, not to revolution the game, and I'm happy to do that
Well, if you have such a clear idea of what is going on then I am confident you will manage to find a solution.
Nice to read that you enjoy the same aspects and do want to keep it. :)
So how long have you known Trigger Rally?
Well, it's about some year that I entered the informatic world, and consequently in the linux and open source world. Trigger-rally was one of the first game I have tryed (and liked).
Hi all. In these two days I have worked on the trigger rally physic. Here I have little patch that I hope will make a little better experience, but maybe the solution I adopted is not optimal yet. Please try compiling and test trigger rally physic with these two modifyed vmath.h and vehicle.cpp files. But please, don't look directly to the code changes before trying this patch. I will explain the changes here later, but I'd like to know if you feel any improvments or not, without knowing where they are. Enjoy:)
EDIT:
This patch is based on the revision 851
Last edit: Emanuele Sorce 2017-01-28
I've tried your changes and my personal impression is that they are not good enough, yet. My observations are:
Good:
Bad (all drift related):
Note that terrains use a friction coefficient of 1.0 for gravel, but up to 1.5 for tarmac (just in case your calculations assume coefficients between 0 and 1 only, and break otherwise). You can see the coefficients in the terrainmap.h file:
https://sourceforge.net/p/trigger-rally/code/851/tree/src/include/terrainmap.h#l52
So you're on the right path but the excess drifting needs to be fixed. In my opinion, tarmac should feel precise as a train on rails.
I am curious what Onsemeliot's impressions are, and also, Emanuele I would like you to say exactly what were your goals with this patch. You fixed the bad landings from what I've seen so good work on that, but what else did you have in mind?
EDIT: fixed the bad formatting of Good/Bad lists above.
Last edit: Andrei 2017-01-28
Andrey, I'm really happy you found something positive. But you also succefully found the bugs that are caused by my non-complete implementation of the code I wrote, but I liked to share the partial code with you, as the remaining part of the problem seems particulary tricky, at least for me. I tryed to fix the problem that at any wheel inclination the grip and the resistance of the ground is the same. I have done a draw to represent the algoritm I have (partially) built.
The problem is that I considered the alpha angle constant at 0 radians. That means that there is a loss of grip when the road is inclinated. To overcome that a bit I made a multiplication of 1.002 of the grip, but that causes problems (wrong audio and dirt effects). The real problem is that I should calculate alpha, but I don't know how yet. I'm working on this however, but I'd liked to make you see what I have done so far because is my first contribution here. :-)
EDIT:
typo: I multiplicated grip of 1.002, not 0.02
Last edit: Emanuele Sorce 2017-01-28
Nice to read that our work over the years did actually restult into something somebody values. :)
Wow, I think you made a great improvement. I don't know what you did but the cars do feel a lot more steady and don't bounce as much when landing after a jump. I have the impression the breacks do work better too. Even in curves the grip is better and this makes it much easier to get back on track.
At first, after compilation, I was uncertain because I lost my configuration file. After I restored the relevant values I enjoy the new physics very much. (But it seems to be rather important to set the "drivingassist" value from "0.33" to "0.55". We should change the default value since in my experience this improves the handling of the cars considerably.)
Do you understand the game physics entirely now? I am asking because if this is the case I can imagine things you could further improve like making trees and roadsigns something you could actually crash into. At the moment it's not optimal since you can drive through them as if there was nothing.
An other possibility would be to enhance the effects of different soil materials ...
Hm, I had the impression of sudden drifts and dust on tarmac too but I thought this was because of me missing it partly. I didn't even encounter the sound issues because I was testing without sound (as I often do).
I'm happy you liked, but as Andrei pointed out, and I confirmed explaining why, I have still to work on this patch to polish it.
Well, let's say yes and no. The codebase is huge for what I used to work on, and is completely new for me. Also the math implied is pretty complex (matrixes, quaternions...). I managed to understand enought here and there where I needed to operate, but for example the part of the code managing the contact of the car with the ground is not yet clear to me (more that unclear, I haven't found where it lurks yet). That code is the one I need to study to obtain that alpha angle (I hope you get something from my previous message where I explained my patch using my ugly english).
It seems to me it lurks in
PVehicle::tick()at vehicle.cpp:931 (sourceforge.net) andPVehicle::updateParts()at vehicle.cpp:1127 (sourceforge.net).Done! I hope that there are no bugs now. Test it if you'd like to! The file I modified are as before vmath.h and vehicle.cpp.
Sorry. I forgot vmath.h