Rick Posted September 10, 2014 Posted September 10, 2014 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? Quote
Haydenmango Posted September 10, 2014 Posted September 10, 2014 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. 1 Quote Check out my game Rogue Snowboarding- https://haydenmango.itch.io/roguesnowboarding
Rick Posted September 10, 2014 Author Posted September 10, 2014 Perfect, that's what I'm looking for. It also looks like I can use 1 shape and set it to many models, which is nice! 1 Quote
Recommended Posts
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.