johnsbro Posted June 10, 2017 Share Posted June 10, 2017 I'm using Matter.js as my physics engine and Pixi as my renderer and under normal circumstances I've been able to get them to work smoothly. However, I'm trying to do something where all of the objects *except* the player character are scaled down to look like the character is now above them. The scaling works visually in Pixi, but I can't get the bodies from Matter.js to go with it, so there are these "ghost objects" that I can't see but if collide with them then the scaled down objects will be moved. Does anyone have any tips for how to resolve this? Let me know if I need to post a gif if that would help explain the problem. Quote Link to comment Share on other sites More sharing options...
Taz Posted June 10, 2017 Share Posted June 10, 2017 Have you tried using "Body.scale(body, scaleFactorX, scaleFactorY)" to scale the Matter.js bodies by same factor? Quote Link to comment Share on other sites More sharing options...
johnsbro Posted June 10, 2017 Author Share Posted June 10, 2017 Yes. but with that method the bodies scale in on themselves. I even tried "Body.scale(body, scaleFactorX, scaleFactorY, {x: 0, y: 0 } )" so that it would match up but that didn't work either. Quote Link to comment Share on other sites More sharing options...
Taz Posted June 10, 2017 Share Posted June 10, 2017 If the problem is cumulative scaling, what about storing scale factor and scaling by the reciprocal of the old scale factor before you scale by the new factor? That's the only thing I can think of but maybe the way they scale is too different Quote Link to comment Share on other sites More sharing options...
johnsbro Posted June 10, 2017 Author Share Posted June 10, 2017 This is in the game loop: ``` below.scale.x *= .5 below.scale.y *= .5 for (let i = 0; i < below.children.length; i++){ Body.scale(map, below.scale.x, below.scale.y, { x: 0, y: 0 }) } ``` below is a PIXI container and map is an array of Matter bodies Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted June 10, 2017 Share Posted June 10, 2017 Why *= ? Quote Link to comment Share on other sites More sharing options...
johnsbro Posted June 10, 2017 Author Share Posted June 10, 2017 I'm multiplying the scale by 1/2 each time to shrink it. It's the same as "below.scale.x = below.scale.x * .5" 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.