Jump to content

Rotate bounding box of follower object


Recommended Posts

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.car.rotate = 45 //?????
        this.path = path;

        //Start following along the predefined path
            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?




Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...