Apply Gravity to an Object
by Brandon Fogerty · in Technical Issues · 06/09/2007 (10:40 am) · 23 replies
Hi. I have added an object to my world view. I placed my object in the sky. How do I apply gravity to it so that it falls to the ground? Thanks in advance!
#2
datablock StaticShapeData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
rotate = true;
maxVelocity = 1;
mass = 50.0;
gravity=100;
rotate = true;
static = false;
gravityMod = 1;
};
However my Torque Logo object doesn't move... it still floats in the sky
06/09/2007 (11:53 am)
Here is my codedatablock StaticShapeData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
rotate = true;
maxVelocity = 1;
mass = 50.0;
gravity=100;
rotate = true;
static = false;
gravityMod = 1;
};
However my Torque Logo object doesn't move... it still floats in the sky
#3
datablock StaticShapeData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
rotate = true;
maxVelocity = 1;
mass = 50.0;
gravity=100;
rotate = true;
static = false;
gravityMod = 1;
};
However my Torque Logo object doesn't move... it still floats in the sky
06/09/2007 (12:15 pm)
Here is my codedatablock StaticShapeData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
rotate = true;
maxVelocity = 1;
mass = 50.0;
gravity=100;
rotate = true;
static = false;
gravityMod = 1;
};
However my Torque Logo object doesn't move... it still floats in the sky
#4
datablock StaticShapeData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
rotate = true;
maxVelocity = 1;
mass = 50.0;
gravity=100;
rotate = true;
static = false;
gravityMod = 1;
};
However my Torque Logo object doesn't move... it still floats in the sky
06/09/2007 (2:12 pm)
Here is my codedatablock StaticShapeData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
rotate = true;
maxVelocity = 1;
mass = 50.0;
gravity=100;
rotate = true;
static = false;
gravityMod = 1;
};
However my Torque Logo object doesn't move... it still floats in the sky
#5
If it is, uncheck it.
Hope that helps.
P.S. I haven't spent much time with gravity in torque, so this might not be the best solution. If you search you might find something better.
06/09/2007 (2:41 pm)
Check to see if your object is static in the world editor.(F3)If it is, uncheck it.
Hope that helps.
P.S. I haven't spent much time with gravity in torque, so this might not be the best solution. If you search you might find something better.
#6
06/09/2007 (2:59 pm)
Where do I go to see if it is static? Also, when I click on the object in Inspector mode, I don't see any attribute to uncheck for being static.
#7
Good luck!
06/09/2007 (4:13 pm)
Press F11 and then click on your item. Then hit F3. You should see some properties about your item on the right. There should be a Misc. Properties category in the middle. Inside that is where the static property can be checked/unchecked. I'm pretty sure this can be done through script but I can't remember how right now, sorry.Good luck!
#8
You have it coded here, so with this code, it shouldn't be static.
06/09/2007 (5:15 pm)
Here is my code
datablock StaticShapeData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
rotate = true;
maxVelocity = 1;
mass = 50.0;
gravity=100;
rotate = true;
[b]static = false;[/b]
gravityMod = 1;
};You have it coded here, so with this code, it shouldn't be static.
#9
06/09/2007 (6:19 pm)
Hey Mike, thanks for the reply. I created a Static object in my world editor. Then I set its datablock to the TorqueLogoItem. And I copied and pasted your code into my server/logoItem.cs. However nothing changed... My TorqueLogo model still floats in the air. Any other ideas? Thanks in advance!
#10
I believe the problems you are having are caused from when you declared what type of datablock your item was. Instead of StaticShapeData, try Datablock ItemData(TorqueLogoItem) ect.
You may still have to check/uncheck your static variable like I told you before, even though you set it to false.
Hope that helps.
06/10/2007 (1:44 pm)
Brandon I am so sorry that I didn't see this before! (Long week)I believe the problems you are having are caused from when you declared what type of datablock your item was. Instead of StaticShapeData, try Datablock ItemData(TorqueLogoItem) ect.
You may still have to check/uncheck your static variable like I told you before, even though you set it to false.
Hope that helps.
#11
06/10/2007 (2:56 pm)
I think you are right Jeremy however if I set it to ItemData as opposed to StaticShapeData, then I can't use the object in my world editor. It only allows me to use the object if it is a StaticShapeObject. Also, I have looked and looked everywhere in my world editor and there is no option anywhere where I can check the object as "Static" or "Not Static". Any ideas? Thank you so much for helping me thus far!
#12
Here is your datablock that I put into one of my scripts.
When I added the Logo into the game, it didn't go into the editor when i hit F3.(that's your problem, right?}
Well I just clicked on another object and then clicked backed and it worked. I had to uncheck the static property though.
The weird thing is only the collision box dropped and not the actual logo. The logo went to the location of the box when the boxed stopped moving or when I checked the static property. Don't know why that is happening.(like i said before, not much experience with gravity in torque)
06/10/2007 (3:37 pm)
Ok I think I got it. Here is your datablock that I put into one of my scripts.
datablock ItemData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
rotate = true;
maxVelocity = 1;
mass = 1;
gravity=100;
rotate = true;
static = false;
gravityMod = 1;
};When I added the Logo into the game, it didn't go into the editor when i hit F3.(that's your problem, right?}
Well I just clicked on another object and then clicked backed and it worked. I had to uncheck the static property though.
The weird thing is only the collision box dropped and not the actual logo. The logo went to the location of the box when the boxed stopped moving or when I checked the static property. Don't know why that is happening.(like i said before, not much experience with gravity in torque)
#13
06/10/2007 (5:56 pm)
I think you are right Jeremy however if I set it to ItemData as opposed to StaticShapeData, then I can't use the object in my world editor. It only allows me to use the object if it is a StaticShapeObject. Also, I have looked and looked everywhere in my world editor and there is no option anywhere where I can check the object as "Static" or "Not Static". Any ideas? Thank you so much for helping me thus far!
#14
06/10/2007 (7:06 pm)
Sorry Jeremy. I don't quite follow. What did you have to do in the world editor exactly to get it to work?
#15
My TorqueLogoItem appears in the world. However gravity does not effect it.
If I change the type to "ItemData" in my script, when I go into my world creator and add Shapes->Items->TorqueLogoItem, The TorqueLogoItem will not spawn into my world. Nothing is added until I change my script back to "StaticShapeData".
Also, can you provide me a screenshot of this place in the world editor where you can check the "Static" option for an object because I don't see that option anywhere. Finally, what version of Torque are you using? I am using 1.5. Thanks so much for all your help Jeremy!
06/10/2007 (7:11 pm)
If my datablock is of type "StaticShapeData", when I go into my world creator and add Shapes->Items->TorqueLogoItem,My TorqueLogoItem appears in the world. However gravity does not effect it.
If I change the type to "ItemData" in my script, when I go into my world creator and add Shapes->Items->TorqueLogoItem, The TorqueLogoItem will not spawn into my world. Nothing is added until I change my script back to "StaticShapeData".
Also, can you provide me a screenshot of this place in the world editor where you can check the "Static" option for an object because I don't see that option anywhere. Finally, what version of Torque are you using? I am using 1.5. Thanks so much for all your help Jeremy!
#16
(sorry don't know how to take screenshots!)
Copy the code in my last post into one of your working scripts.(Its basically your script but try it just in case)
Then in the game press F11, then F4. Go to shapes,items, and then the logo.
Put the logo in the air or something and while it is still selected, go to the window button at the top of the screen. One of the options in the window button will be World Editor Inspector F3. Click that and you'll see the properties of the logo. One of them is the static option.
Now it should fall.
P.S. Since you have torque 1.5 you may want to look into Rigid Shapes too, they're pretty useful.
06/11/2007 (10:38 am)
I have torque 1.5 too and this seems to work for me. So, let me try to clear up what I meant before. (sorry don't know how to take screenshots!)
Copy the code in my last post into one of your working scripts.(Its basically your script but try it just in case)
Then in the game press F11, then F4. Go to shapes,items, and then the logo.
Put the logo in the air or something and while it is still selected, go to the window button at the top of the screen. One of the options in the window button will be World Editor Inspector F3. Click that and you'll see the properties of the logo. One of them is the static option.
Now it should fall.
P.S. Since you have torque 1.5 you may want to look into Rigid Shapes too, they're pretty useful.
#17
When I click on the Logo object now in the World Creator. it won't spawn the object. I have posted a snapshot to show you.
As far as the inspector properties goes, I don't have the Static option. Here is a list of the options that I do have.
SimBase
---------------->CanSaveDy...
---------------->InternalName
Transform
---------------->position
---------------->rotate
---------------->scale
Misc
---------------->nameTag
---------------->datablock (When I expand this, there is no "Static" option)
Dynamic Fields
But see the problem I am having is two fold. The world editor won't even let me spawn the torque logo as long as I have its datablock defined as a "ItemData". As soon as I revert back to "StaticShapeData" it will let me spawn it. Any ideas?
Here is the link to what I see.
http://www.brandonfogerty.com/my_stuff/images/world.JPG
PS: To take a snap shot of your screen, press your "Prnt Scrn" button on your keyboard and then do a Ctrl + V in MsPaint.
Thanks in advance!
06/11/2007 (4:37 pm)
I tried those things. I changed my code as you told me to.When I click on the Logo object now in the World Creator. it won't spawn the object. I have posted a snapshot to show you.
As far as the inspector properties goes, I don't have the Static option. Here is a list of the options that I do have.
SimBase
---------------->CanSaveDy...
---------------->InternalName
Transform
---------------->position
---------------->rotate
---------------->scale
Misc
---------------->nameTag
---------------->datablock (When I expand this, there is no "Static" option)
Dynamic Fields
But see the problem I am having is two fold. The world editor won't even let me spawn the torque logo as long as I have its datablock defined as a "ItemData". As soon as I revert back to "StaticShapeData" it will let me spawn it. Any ideas?
Here is the link to what I see.
http://www.brandonfogerty.com/my_stuff/images/world.JPG
PS: To take a snap shot of your screen, press your "Prnt Scrn" button on your keyboard and then do a Ctrl + V in MsPaint.
Thanks in advance!
#18
Save this code into a new file and name it something like logo.cs or whatever.
Put it in your server scripts and make the normal adjustments to game.cs(Don't forget to delete game.cs.dso)
Start your your game up and find out what the handle of your avatar is.
(Press F8 to go into fly mode and then look at the number written by your player, but make sure its not the handle of a spawn sphere. I do that a lot :) )
Ok than press the tilde key(~) and type InsertLogo(yourplayer'shandle)
this should spawn the item above your player's head and it will slowly fall down.
Hope it works
(don't worry I tested it so I know it does work)
06/11/2007 (5:46 pm)
Don't know why the ItemData doesn't spawn, so lets try it a different way.Save this code into a new file and name it something like logo.cs or whatever.
datablock ItemData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
rotate = true;
maxVelocity = 1;
mass = 1;
static = false;
gravityMod = 1;
};
function InsertLogo(%player)
{
%logo= new Item(){
datablock = TorqueLogoItem;
};
MissionCleanup.add(%logo);
%playertrans = %player.getTransform();
%playerx = getword(%playertrans, 0);
%playery = getword(%playertrans, 1);
%playerz = getword(%playertrans, 2);
%playerz = %playerz + 50;
%logo.setTransform(%playerx SPC %playery SPC %playerz SPC "0 0 1 0");
return %logo;
}Put it in your server scripts and make the normal adjustments to game.cs(Don't forget to delete game.cs.dso)
Start your your game up and find out what the handle of your avatar is.
(Press F8 to go into fly mode and then look at the number written by your player, but make sure its not the handle of a spawn sphere. I do that a lot :) )
Ok than press the tilde key(~) and type InsertLogo(yourplayer'shandle)
this should spawn the item above your player's head and it will slowly fall down.
Hope it works
(don't worry I tested it so I know it does work)
#19
06/11/2007 (7:39 pm)
Nope.... doesn't work. I wonder if my version of Torque is a buggy version or something...
#20
function StaticShapeData::create(%data)
{
%obj = new StaticShape() {
dataBlock = %data;
};
return %obj;
}
Hmm.... So I figured that was why I couldn't spawn anything other than the StaticShapeData type. So added the function again and made a couple of small changes.
function ItemData::create(%data)
{
%obj = new Item() {
dataBlock = %data;
};
return %obj;
}
Saved it, then opened up the world editor again and added my TorqueLogo. What do you know? The Laws of gravity fell into place! ;)
Thanks for all your help Jeremy. I know I probably became annoying after a while but thanks again!
06/11/2007 (8:46 pm)
Hey Jeremy, thanks for all your help but I figured out what was wrong. You were right, I needed to use the ItemData type however I got curious and looked in my editor.cs file and found the following snippet.function StaticShapeData::create(%data)
{
%obj = new StaticShape() {
dataBlock = %data;
};
return %obj;
}
Hmm.... So I figured that was why I couldn't spawn anything other than the StaticShapeData type. So added the function again and made a couple of small changes.
function ItemData::create(%data)
{
%obj = new Item() {
dataBlock = %data;
};
return %obj;
}
Saved it, then opened up the world editor again and added my TorqueLogo. What do you know? The Laws of gravity fell into place! ;)
Thanks for all your help Jeremy. I know I probably became annoying after a while but thanks again!
Torque Owner Jeremy Jenkins
So it would look something like this:
datablock ItemData(Crossbow)
{
category = "Weapon";
className = "Weapon";
shapeFile = "~/data/shapes/crossbow/weapon.dts";
mass = 1;
gravityMod = 1; (negative makes is float up)
You might also want to look at this:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1723
I haven't tried it myself yet, but it looks interesting.