Jump to content

Recommended Posts

Posted

Shape* shape = Shape::Box(0,0,0, 0,0,0, 10,1,10);

ground->SetShape(shape);

shape->Release();

 

 

What's the proper way to remove a shape from an entity? Do I just pass in NULL? Is that good enough?

 

I assume calling SetShape() increases the ref counter? So by releasing it afterwards the ref count is 1, and if I call SetShape(NULL) it'll reduce it to 0?

Posted

Yep. I use SetShape(nil) in Lua and it works fine. It also reduces the shapes ref count to 0. I tested it with DebugPhysicsMode on to make sure. What I do for weapons is have them store their shape at the start like this -

 

function Script:Start()

self.shape=self.entity:GetShape()

self.shape:AddRef()

end

 

Then when my player picks up the weapon its shape is reduced to 0 by using self.entity:SetShape(nil). If I drop the weapon it gets its shape back from the self.shape I stored at the start. Like this -- self.entity:SetShape(self.shape). Then if I set the weapons shape to nil again I still have self.shape referenced so it can be used over and over again.

  • Upvote 1

Check out my game Rogue Snowboarding- 

https://haydenmango.itch.io/roguesnowboarding

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.

×
×
  • Create New...