Gravity force equivalent

Posted By: deianthropus

Gravity force equivalent - 04/05/10 21:27

I am trying to set a force equal to gravity... however I am not having much success. For a particular entity, I want to exert a force equal to gravity in order to maintain its .z, but so that it can still be acted upon in a collision.

i've tried setting a force to (0,0,(obj_mass*-1*grav) because f(grav)=mg and the new vector must oppose gravity. However, this does not work for me. What am I missing?
Posted By: deianthropus

Re: Gravity force equivalent - 04/06/10 19:44

I can simulate the effect of gravity for the entity, and that works fine, but it seems kinda redundant to have to assign it for each entity I want gravity to apply to.

(the object in question can only use the gravity counter-force at certain times and in varying amounts according to a coefficient of the 1:1 antigrav force, but that's not the issue.)

Can anyone at least tell me the algorithm the gravity function uses? because it doesn't seem to follow the F = ma; a=f/m rule of acceleration and force, or maybe the force parameter for phent_addcentralforce is something other than the force equivelant to the mass times the acceleration? I just don't get it.
Posted By: painkiller

Re: Gravity force equivalent - 04/08/10 18:06

the gravity function accelerates all physics entity with the direction and acceleration that you have set on the vector. Example: if you set ph_setgravity(0, 0, -1); your entities will go down with an acceleration of -1 quant per sec per sec
Posted By: deianthropus

Re: Gravity force equivalent - 04/08/10 19:21

That's how I interpreted the manual, but my calculations did not succeed along those guidelines. for example, if I have an entity with mass 15, and my gravity is -386 (z), then I apply a force of 386 * 15 (m*g = weight = force of gravity), but this does not bring my acceleration to 0, as one would reason it should. The object continues to fall to the floor.
Posted By: muffel

Re: Gravity force equivalent - 04/08/10 20:11

I have tested it on my own.
The code:
Click to reveal..

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////
ENTITY *look_at;
VECTOR direction;
action my_action()
{
   look_at = me;
   set(my,SHADOW|CAST);
   while(!key_space)wait(1);
   if(0==phent_settype(me,PH_RIGID,PH_BOX))beep();
   phent_setmass(me,10,PH_BOX);
   phent_setdamping (me, 0, 0 );
   phent_setelasticity (me, 50, 0);
   phent_setfriction (me, 50 );
   phent_addcentralforce(me,vector(0,0,386*10));
   while(me)
   {
	phent_getvelocity (me, direction, nullvector ); 
	wait(1);
   }
}
function main()
{
  vec_set(screen_size,vector(800,400,0));
  vec_set(screen_color,vector(50,1,1)); // dark blue
  vec_set(sky_color,vector(50,1,1)); // dark blue
  video_window(NULL,NULL,0,"My New Game");
  d3d_antialias = 1;
  shadow_stencil = 3;
  
  level_load("");
  vec_set(camera.x,vector(-250,0,50));
  vec_set(camera.pan,vector(0,-15,0));
	ph_setgravity (vector(0,0,-386 ));
	ent_create("box.mdl",nullvector,my_action);

}




if the line while(!key_space)wait(1); is comment out everything works like expected.
but if it isn't comment out, nothing works as expected.
the object accelerats downwards.

my only explaination is that the problem is caused by ODE itselfs.

muffel
© 2024 lite-C Forums