Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,008 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
A6 phys.. how to remove forces after adding? #140147
07/08/07 22:01
07/08/07 22:01
Joined: Jul 2007
Posts: 24
N
noobie86 Offline OP
Newbie
noobie86  Offline OP
Newbie
N

Joined: Jul 2007
Posts: 24
i'm making a car sim.. tried usin Newton but car kept drifting.. tried xxxGuitar's advice (sir thanks for the advice by the way ) but was only partially successful.. i'm now trying A6 physics.. here's the lowdown on what i'm trying to get from the physics..

1. fun physics rather than realistic physics.. i.e. car should be fun to drive even if not accurate.. Newton is so accurate that some fun element gets missed (in my opinion that is )..
2. Physics applied to car body only. Not to tires, glass etc.. all tat is too complicated for me Tires are just attached in a single model.
3. should maintain momentum for quite some time and should have low turning radius

here's the code i've written (for the body). Pretty simple and works well till i take a turn, then it gets awkward.. (lines starting with '//' are parts of an older code i tried and ditched, 'merc' refers to the car body)--


//Code start

var fwd_force[3];
var turning_force[3];
var pan_force_count;
var translate_axis[3] = 0,0,0;
var rotate_axis[3] = 10,0,0;
var merc_linvel[3];
var merc_angvel[3];
var lin_friction;
var ang_friction;
var earth_grav[3] = 0,0,-386;

var mass;
var grav;
//var flag_nopan=1;


action physics_merc
{

phent_settype(my,PH_RIGID,PH_BOX);

mass = phent_setmass(my, 8, PH_BOX);
grav = ph_setgravity(earth_grav); //mass and gravity set, working well


while(1)
{
camera.x = my.x - 200*cos(my.pan);
camera.y = my.y - 200*sin(my.pan);
camera.z = my.z+30;
camera.pan = my.pan; //camera is fine

//my.pan = my.pan%90;

fwd_force[0] = 4000*(key_cuu-key_cud);
phent_addforcelocal(my,fwd_force,translate_axis); //'engine' force

phent_getvelocity(my,merc_linvel,translate_axis); //friction force
lin_friction[0] = -2*merc_linvel[0];
//lin_friction[1] = -2*merc_linvel[1];

if(!key_any) //decrease momentum when no key pressed..
{ phent_addforcelocal(my,lin_friction,translate_axis); }


if(key_cul || key_cur)
{
if(pan_force_count<30) //slowly increase torque applied
{
pan_force_count+=1;
turning_force[2] = pan_force_count*(key_cul-key_cur);
phent_addtorquelocal(my,turning_force);
}
}

if(!key_cul && !key_cur) {pan_force_count = 0;}


wait(1);
}
}

//Code end

i think the major problem here is that the forces added on 'if(!anykey)' don't get removed and car continues to move under the influence of these forces.. is there any way to remove the forces?

i tried adding opposite forces but that doesn't work very well.. maybe i couldn't get the magnitude right..

i haven't added code yet for resetting on flip-over or no forces applied after a critical tilt or roll.. i'll do that once i can solve the force removal problem..

Re: A6 phys.. how to remove forces after adding? [Re: noobie86] #140148
07/10/07 01:22
07/10/07 01:22
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
I'm sure you're looking for something like GTA car physics. Everyone does...

I got into a big discussion on the pro's and con's of Newton vs. 3DGS not too long ago. I prefer newton, but when working with large levels, newton can take quite some time to load, if it even loads at all...

As I've said before, newtons car physics are pretty good, you simply have to adjust the settings properly. Newton has a special method for tires. In most physics engines, when an object spins too fast, it "explodes" (not literally, it just becomes unstable and does unexpected things. Newton simply approximates the collision of these tires, so an explosion is unlikely.

One good trick for using newton is to create an short, invisible box entity for the undercariage of the car, with the proper mass of the car, and the regular car body with a much lower mass. This will lower the cars center of gravity, and in turn make flipping-over less likely. However, this will require a little bit more work

Good luck bro, hope I provided some asistance...


xXxGuitar511
- Programmer
Re: A6 phys.. how to remove forces after adding? [Re: xXxGuitar511] #140149
07/10/07 07:02
07/10/07 07:02
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Quote:

i think the major problem here is that the forces added on 'if(!anykey)' don't get removed and car continues to move under the influence of these forces.. is there any way to remove the forces?


when you add a force, it doesn't stay there. it's just applying a force to a point on an object in one instant.

julz


Formerly known as JulzMighty.
I made KarBOOM!

Moderated by  HeelX, Spirit 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1