Sign in to follow this  

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 =; 
        graphics.lineStyle(1, 0xff0000, 1);
        curve.draw(graphics, 128);
        graphics.fillStyle(0x00ff00, 0.5);
        = game; =, 0, 0, texture);

        //Set the size of the bounding box,35, true);   ; = 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?




Share this post

Link to post
Share on other sites

Based on the `` 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.