Jump to content

Constant circular motion - falls slightly out of circle at end of each rotation


seiyria
 Share

Recommended Posts

So I'm currently trying to make a sprite that just moves around in a circle forever. I was using the example found here: http://examples.phaser.io/_site/view_full.html?d=physics&f=angular+velocity.js&t=angular%20velocity as a base.

 

My code for creating said sprites looks like this:

        @map.createFromObjects 'PlatformLayer', 45, 'platforms', 0, true, false, @circPlatforms        @circPlatforms.setAll 'body.allowGravity', false        @circPlatforms.setAll 'body.immovable', true        @circPlatforms.forEach ((platform) =>            platform.radius = (+platform.radius or 1)            platform.rotAngle = +platform.rotAngle or 0            @game.time.events.loop 1, ((platform) =>                 platform.body.velocity.x = 0                platform.body.velocity.y = 0                @game.physics.velocityFromAngle platform.rotAngle, platform.radius*32, platform.body.velocity                platform.rotAngle = ++platform.rotAngle % 360            ), @, platform        ), @

In Tiled I assign a rotAngle (the current spot in the rotation) and a radius (the number of tiles I'd like it to cover). Unfortunately, I have no idea what I'm doing. I can't seem to get the sprite to move faster along the circle (increasing the speed parameter just seems to make the circle larger and body.angularRotation, body.angularAcceleration, and body.speed don't seem to help either), and I'm not at all certain how to ensure the radius in tiles (a tile for me is 32x32). Also, when this sprite gets to the end of a full rotation, it is not where it started, it's somewhere off to the top-left. I can't figure out how to determine why it's doing that. Overall, I'm just sorta confused about this whole ordeal. Any ideas?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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