ambidex Posted March 28, 2015 Share Posted March 28, 2015 I've been working with P2.js within Panda.js for a while now and need it for some complex collisions (like concave shapes). While I can make everything work like clockwork, there is one this I'm not able to figure out: how do I resize my body's shapes? I would think body.shapes[0].height would do the trick, but after the body has been added to the World, this will not be used. I'm having the feeling that this should actually be possible. Quote Link to comment Share on other sites More sharing options...
schteppe Posted March 29, 2015 Share Posted March 29, 2015 You're right. The p2.Rectangle class constructor instantiates a p2.Convex with 4 vertices, see https://github.com/schteppe/p2.js/blob/master/src/shapes/Rectangle.jsYou need to update the vertices instead. Something like:shape.vertices[0][0] = -width/2;shape.vertices[0][1] = -height/2;...etcThen you need to update some properties of the Convex:shape.updateTriangles();shape.updateCenterOfMass();shape.updateBoundingRadius();shape.updateArea();Sorry for the clunky API Quote Link to comment Share on other sites More sharing options...
ambidex Posted April 5, 2015 Author Share Posted April 5, 2015 Hi Schteppe, Thanks a lot for your reply. Just implemented this into my game, seems to work! Though the Panda.js p2.js debugdraw seems to not be prepared for these shape updates. Might have to look into that one day. Though, while implementing this I was realizing that this is a really heavy weight solution for my situation. I've got a playground that is to be scaled, in this playground are sprites that have these corresponding p2.js bodies so they have to be resized too. Since the GUI shouldn't be scaled, and I use bodies for those sprites too, I scale the bodies in the playground manually. I'm now thinking of creating separate Worlds for the playground and GUI, so I can simply change the playground's World ratio. Would you agree on that being the right approach? Edit: I'm starting to have the feeling World.ratio does not exist in p2's World object? I'm not sure, but I also think there is no support for complete World resizing? Quote Link to comment Share on other sites More sharing options...
schteppe Posted April 7, 2015 Share Posted April 7, 2015 Hi again, There's no support for "ratio" it in the p2.js World, I don't know about Panda.js. Rigid bodies aren't supposed to change at all over time, it's often better to recreate them. In many cases there's a physics-to-rendering scale ratio that you can set somewhere, probably in your game framework. Stefan Quote Link to comment Share on other sites More sharing options...
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.