Jump to content

accelerationFromRotation Unexpected Behavior?


Styles2304
 Share

Recommended Posts

Forgive me if I don't use the correct terminology and also if this is solved elsewhere. I'm still new enough to this that I'm not quite sure what questions to ask and/or what to search for...With that said, if I haven't provided adequate information please let me know.

I copied the asteroid movement for a game I'm working on but it doesn't seem to act that way you would expect. When I use accelerationFromRotation on the body of the sprite, if the sprite is point at an angle, it moves the sprite in an arc. I didn't notice this until I added a particle trail to the ship. When you're accelerating you can actually see the particle trail start to skew left or right. I've taken a screen shot to display the issue:

UaG5UDn.png

This happens more extreme at some angles vs others. In some cases, the trail seems to be off by as much as 30 degrees. Also, what I have logged in the console is `body.acceleration`.

This is the code for the acceleration, and rotation right out example and modified to reference my sprite:

            if (this.controls.u) {
                this.physics.arcade.accelerationFromRotation(this.player.rotation, 300, this.player.body.acceleration);
            } else {
                this.player.body.acceleration.set(0);
            }

            if (this.controls.l) {
                this.player.body.angularVelocity = -300;
            } else if (this.controls.r) {
                this.player.body.angularVelocity = 300;
            } else {
                this.player.body.angularVelocity = 0;
            }

 

Just a little on the particle emitter to make sure I'm providing the necessary info: The gravity is set to zero and it has no velocity applied to it. It creates the particle and relies on the ship moving to create the trail to allow for visual deceleration.

Link to comment
Share on other sites

So I did some more digging around, if you swap out the space background on the asteroid movement example for one with a grid, you can see the exact same behavior. Is this a bug then? As best I can tell, if you're not at some variant of 45 degrees, more y velocity is applied than is necessary. If you're pointing "down" then more y velocity, if you're point "up" then less.

Are my findings here accurate and, if so, should I post a bug report or is there some sort of work around?

Link to comment
Share on other sites

Yes, I am using drag. Is that the culprit? I will definitely check out that plug in as soon as I can. Thank you.

 

-- EDIT --

Demo

I haven't started using this plugin on my setup yet but if you look at the demo provided you can see exactly the issue I'm talking about. The direction of the velocity always bypasses the direction of the acceleration...and it definitely seems to be related to drag. At least I'm narrowing down the cause.

Link to comment
Share on other sites

Try removing drag and see if it looks better.

In Arcade Physics the drag vector is applied separately on each axis. With asteroids-type movement that tends to bend velocity toward the diagonal at high speeds and away from the diagonal at low speeds.

You could apply your own drag with something like

if (this.controls.u) {
    this.physics.arcade.accelerationFromRotation(this.player.rotation, 300, this.player.body.acceleration);
} else {
    this.physics.arcade.accelerationFromRotation(this.math.reverseAngle(this.player.rotation), DRAG, this.player.body.acceleration);
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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