Jump to content

Gravity on initialization


Rekindled Phoenix
 Share

Recommended Posts

I'm looking at the Oil drum object, and even the cage lights which are initialized with gravity in the Sandbox editor, and can't replicate the same results! What is wrong with this script?

 

 

require("scripts/class")
local class=CreateClass(...)

function class:CreateObject(model)
local object=self.super:CreateObject(model)

model:SetKey("mass",1)
model:SetKey("collision",COLLISION_PROP)

-- OR

function object:Init()
	self.model:SetKey("mass",1)
	self.model:SetKey("collision",COLLISION_PROP)
end

object:Init()
end

Link to comment
Share on other sites

there's nothing wrong with the script that I can see concerning SetBodyGravityMode() and the gravity option is checked for me, which it should be since a body's gravity is enabled by default. So even just a script that contains just the first two lines should make the gravity option be checked in the properties. i would try restarting the editor and placing another instance of the model into the scene.

 

The only problems i see in that script is the fact you are using the COLLISION_PROP variable when its not being defined and a key that doesn't exist in the class script. you need to add this line if you are going to use that variable:

require("scripts/constants/collision_const")

or just set the variable to a 1.

 

and then change the key to match what is being used in the class script:

model:SetKey("collisiontype",1)

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Unfortunately, that doesn't work.

(When dragged into the editor, properties mass and gravity are set appropriately, but the object never moves / falls)

 

Look at the script for the fixture_hanginglight object. There is no reference to any include file, though they are used and work correctly.

Same goes for the oil drum, which doesn't specify keys at all, yet is initialized with gravity.

 

I'm completely confused...

Link to comment
Share on other sites

You do not need to include any other files if you just want the gravity property key checked. The required file i mentioned above is for actually setting the collision type property correctly.

 

If you are referring to it actually responding to physics and falling down, then you need a PHY body created from phygen.

 

I cannot replicate the issue. It works every time correctly even with just the first two lines. You dont happen to have an INI file for that model with the gravity set to 0 by chance?

 

You could also try to set the variable yourself:

object.model:SetKey("gravity",1)

 

Other than that, the only thing i would suggest assuming you haven't modified the class.script is to download a clean copy of the SDK.

 

**EDIT - you have edited your post since i commented. Dynamic objects must have their PHY bodies created with phygen. The PHy body created by the editor is for static models ONLY.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Thanks Macklebee, I'm going to try:

 

- new PHY (not generated by Sandbox)

- new INI (non-existent)

 

Then if that doesn't work I'll have to update my SDK files.

I'll post later when all that is done.

 

Just creating a new PHY body with phygen should resolve your issue. I just mentioned the INI file because it seemed like you were implying that the gravity property was not being checked in the dialog and it made no sense that it would not be.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

It did! That solved it! Apparently the method that the Sandbox Editor uses creates PHY files that, for some reason, aren't affected by gravity.

 

Should this be reported as a bug?

 

No. Like I said above, the PHY body created by the Editor is ONLY for STATIC models. :)

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...