Jump to content

Setting the Prop Collision for Models in Code


dhutchison
 Share

Recommended Posts

For each of the models I am using in LeadWerks (e.g., object.gmf), I have created an accompanying .lua file (e.g., object.lua) with the following code:

 

require("scripts/class")

local class=CreateClass(...)

 

When I open the Properties Inspector for a model in the editor, I need to manually set the Collision to "Prop".

 

What line(s) I should add to the code above, so I don't have to set this up manually each time? Thanks.

Link to comment
Share on other sites

or just use those two lines like you have them and then make an INI text file for each of your models standard settings that would be found inside the class script/property dialog:

collisiontype = "1"
mass = "10.0"
etc... etc...

 

and then if you create a new instance of the object in a new scene it will automatically load these values.

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

or...

 

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

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

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 3 months later...

When I add a copy of my stone model into my scene, the lua script (Josh posted) runs and I get the attached pic...

 

I originally used an INI file, and physics in the editor didn't work.

 

Any suggestions?

 

Hi,

Did you run that from script editor screen? (with F5 or Run)

Link to comment
Share on other sites

Yes, I ran that code using the editor.

 

The code also seems to be automatically run when I add the object into the world.

 

I still am a n00b at Lua, what do I do to solve this problem?

 

Do not run object scripts. Only save object scripts then add the object into the world.

 

You can run gamescripts like driver.lua or fpscontroller.lua in the editor. Or you can run standalone scripts like example1.lua from the Script Editor located in the SDK root directory.

 

and by the way, my way is better than Josh's example because it actually sets the properties dialog as well as setting the collision type. :)

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...