Sign in to follow this  
VicFirth

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.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: 

problem.png.5752ade8df97c055ac375d2c1add5732.png

but what I get is this:

1550696130_problem2.png.ddb1501f735ff39c555c0a877bf16feb.png

 

How can I achieve that with a follower?

 

 

Thanks.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.