Datamosh Posted March 21, 2017 Share Posted March 21, 2017 Hello! I need to change/adjust the collision rectangle when the entity crouches. I guess that I need to use addShape and setShape but I do not understand how to do it. Can anybody help me with an example or snippet? Thanks! Quote Link to comment Share on other sites More sharing options...
Datamosh Posted March 21, 2017 Author Share Posted March 21, 2017 I solved the problem by deleting the contents of player.body.shapes and adding a new shape using setShape. Example: player.body.shapes = [] player.body.addShape(new me.Rect(0, 0, 16, 16)) Quote Link to comment Share on other sites More sharing options...
Parasyte Posted March 22, 2017 Share Posted March 22, 2017 There's a public API for removing shapes: http://melonjs.github.io/melonJS/docs/me.Body.html#removeShapeAt You can also change the shape in-place (and save yourself a bunch of CPU cycles and garbage collection overhead, if you're doing this often): http://melonjs.github.io/melonJS/docs/me.Body.html#getShape http://melonjs.github.io/melonJS/docs/me.Polygon.html#setShape 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.