Game Development Community

Gravity

by Skylar Kelty · in Torque Game Engine · 03/31/2006 (6:47 am) · 4 replies

Hi,

I have added the gravity mod to our game but cant figure out how to add gravity to objects like rocks. How do I do it?

#1
03/31/2006 (7:35 am)
I used this resource:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1723

And on those objects that I wanted to set the gravity for, I created ShapeBase definitions in script and set their gravity in their onAdd methods from a global variable I stored in the mission file.

In other words, in my old asteroid class (before I switched it to use a destructable RigidShape), I created a ShapeBase class for it, and it's onAdd method looked something like this (I'm typing this from memory -- beware):

function Asteroid::onAdd(%this,%obj)
{
%obj->setGravity($GlobalGravity);
}

In my mission files I manually added an assignment to $GlobalGravity at the very end (outside the object definitions) like this:

$GlobalGravity = 0; //for space

or

$GlobalGravity = -20; //for Earth

or

$GlobalGravity = -10; //for somewhere like Mars

Though I didn't usually set gravity or use asteroids anywhere but in space, I use the same $GlobalGravity variable to set gravity for all players and AI, vehicles, etc...
#2
04/01/2006 (1:11 am)
Thanks for the advice but:

My objects dont have datablocks though - they are static and I have tried many times to get them to use datablocks but I cant get it to work so I can't use a function, Do I need to put the globalgravity outside the last } ? beacuse the mission crashes if i put it anywhere else. I cant use functions for my objects beacuse they are not scripts.

that is the resource i used btw.
#3
04/01/2006 (4:08 am)
Ok they now use datablocks and I have added

%obj.setGravity(-20);

to

function StaticShapeData::onAdd(%this,%obj)
#4
04/02/2006 (11:14 am)
Doesnt work tho