How should I implement gravity wells?
by Jim Rowley · in Torque Game Engine · 06/24/2003 (10:40 am) · 23 replies
I'm thinking of implementing gravity wells in my torque based space game. I have two current thoughts on how to implement them. One, have my spacevehicle class search through the server list of gravity well objects and add in the physical forces for each in its updateForces function. Two, have the gravity well objects themselves search a radius and alter the forces on each object within their pull. Which approach would be most cost-effective if I generally have many spacevehicle objects and few gravity wells in the world?
#22
I am going to qualify my code at this time. The code I have included above should be taken with a big grain of salt. Feel free to use it and hack on it if you would like, but treat it as if I'm giving it to you 'AS IS'. There are still a couple of drawbacks with the code above. First, as I've noted a few times, it can only be applied on server objects (which doesn't lend itself to clients being able to predict very well). Second, I'm finding that the large masses required to exert gravity are becoming a burden, and even too large for torque at times which uses size 'float' (F32) for most everything instead of 'double'. Along this line of thought you can scale the gravity effects to work from smaller masses by increasing the Universal Gravitational Constant in the code (where it reads 6.67E-11 : try 6.67 instead and then masses should be much smaller to work). As my work and code for this is growing I will probably not post anything more on it unless someone out there can't live without it. Thanks all.
07/23/2003 (2:53 pm)
Ok ...I am going to qualify my code at this time. The code I have included above should be taken with a big grain of salt. Feel free to use it and hack on it if you would like, but treat it as if I'm giving it to you 'AS IS'. There are still a couple of drawbacks with the code above. First, as I've noted a few times, it can only be applied on server objects (which doesn't lend itself to clients being able to predict very well). Second, I'm finding that the large masses required to exert gravity are becoming a burden, and even too large for torque at times which uses size 'float' (F32) for most everything instead of 'double'. Along this line of thought you can scale the gravity effects to work from smaller masses by increasing the Universal Gravitational Constant in the code (where it reads 6.67E-11 : try 6.67 instead and then masses should be much smaller to work). As my work and code for this is growing I will probably not post anything more on it unless someone out there can't live without it. Thanks all.
#23
07/30/2003 (8:46 pm)
Well I finally have a bit of code that works on the client and server which I can possibly post as a resource 'when it is done', hehe, never!! But really, I may submit the resource after a bit. When it is complete, vehicles will be able to exert gravity on all other vehicles or just one other (tractor beam). Its coming together nicely. I know tractor beams can be written in a much simpler manner than this, but I'm creating planets and ships which can move, be controlled, collide, and exert gravity on vehicles, so I'm implementing this within my spacevehicle code.
Torque 3D Owner Jim Rowley
Your idea is exactly the 'other method' which I was originally going to persue for this. I've decided its not exactly what I want for my current project because I want dynamic collideable gravity wells (think planets in motion) I am currently using flyingvehicles as gravity wells to do this, and its starting to work out as it is.
The primary drawback with the current code is that I can only do this force update on the server because the mission group isn't proper on the clients. I want the clients to properly predict vehicle motion with gravity effects. My thought is to scopealways these special flyingvehicles (gravity wells) so that clients will have them all, but the clients will also need a list of them for this code and I don't think the missiongroup will work as a gravitywell list for clients because the clients have ghosted copies of the gravitywell objects, each with their own id's, etc. and not part of a group.
Is my thinking screwed on this? I was trying to run my project as both a dedicated server and a client to test these things, but I had problems getting that connection to work out too. How do I do this? -connect as a command line option doesn't seem to be implemented, and there seems to be no "connect" script function in my build (my code is using the HEAD version as of a few months ago). How the heck do I connect to a local server on my same PC to test this stuff?
I think I create these barriers in my subconscience to make my development experience more exciting ;)