VicFirth Posted December 3, 2018 Share Posted December 3, 2018 Hi Everyone, I want to rotate my bounding box of my follower object that I've created. Is this even possible? If so, how to do it? This is a little snippet of my code: class Car { constructor(game, texture, path){ var curve = new Phaser.Curves.Path(game.cache.json.get(path)); var graphics = game.add.graphics(); graphics.lineStyle(1, 0xff0000, 1); curve.draw(graphics, 128); graphics.fillStyle(0x00ff00, 0.5); this.game = game; this.car = this.game.add.follower(curve, 0, 0, texture); //Set the size of the bounding box this.car.setSize(0,35, true); this.game.physics.world.enableBody(this.car); this.car.rotate = 45 //????? this.path = path; //Start following along the predefined path this.car.startFollow({ duration: 7000, positionOnPath: true, rotateToPath: true, verticalAdjust: true }); } So what I want is this: but what I get is this: How can I achieve that with a follower? Thanks. Link to comment Share on other sites More sharing options...
Telinc1 Posted December 3, 2018 Share Posted December 3, 2018 Based on the `physics.world.enableBody` in the code, it looks like you're using Arcade Physics. If that's the case, keep in mind that Arcade Physics only support collision between axis-aligned bounding boxes (AABBs) and circles, i.e. you can't rotate bodies. If you need rotation, look into a more complicated physics engine such as Matter.js (it's available out-of-the-box). Phaser also supports Impact Physics, but I've never used them and I don't know if they support rotation. You could also combine a library like SAT.js with Arcade's collision handlers to pull this off, but it's likely a lot more complicated than switching physics engines, especially if you're early in development. VicFirth and samme 2 Link to comment Share on other sites More sharing options...
Recommended Posts