Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprites flying out a certain distance and then falling #22

Closed
iCodeForBananas opened this issue Sep 14, 2016 · 2 comments
Closed

Sprites flying out a certain distance and then falling #22

iCodeForBananas opened this issue Sep 14, 2016 · 2 comments

Comments

@iCodeForBananas
Copy link

iCodeForBananas commented Sep 14, 2016

https://streamable.com/fak3

Happens on https://rangersteve.io when shooting. Maybe I should be specifying special slope properties just for bullets?

How I'm shooting the bullets

    let bullet = this.bullets.getFirstDead()
    bullet.body.gravity.y = -GameConsts.BULLET_GRAVITY // 850
    bullet.height = 2
    bullet.width = 40
    bullet.reset(x, y)
    let pointerAngle = this.game.physics.arcade.moveToPointer(bullet, currentWeapon.bulletSpeed) // currentWeapon.bulletSpeed === 2300
    bullet.rotation = pointerAngle

How I'm creating the bullets

    this.bullets = this.game.add.group()
    this.bullets.createMultiple(30, 'bullet')
    this.bullets.setAll('checkWorldBounds', true)
    this.bullets.setAll('outOfBoundsKill', true)

    this.physics.arcade.enable(this.bullets)
    this.game.slopes.enable(this.bullets)
    this.bullets.forEach(function(bullet) {
        bullet.body.height = 15
        bullet.body.width = 15
        bullet.height = 2
        bullet.width = 40

        // Define some shortcuts to some useful objects
        var body = bullet.body

        // Update player body properties
        body.drag.x = GameConsts.SLOPE_FEATURES.dragX
        body.drag.y = GameConsts.SLOPE_FEATURES.dragY
        body.bounce.x = GameConsts.SLOPE_FEATURES.bounceX
        body.bounce.y = GameConsts.SLOPE_FEATURES.bounceY

        // Update player body Arcade Slopes properties
        body.slopes.friction.x = GameConsts.SLOPE_FEATURES.frictionX
        body.slopes.friction.y = GameConsts.SLOPE_FEATURES.frictionY
        body.slopes.preferY    = GameConsts.SLOPE_FEATURES.minimumOffsetY
        body.slopes.pullUp     = GameConsts.SLOPE_FEATURES.pullUp
        body.slopes.pullDown   = GameConsts.SLOPE_FEATURES.pullDown
        body.slopes.pullLeft   = GameConsts.SLOPE_FEATURES.pullLeft
        body.slopes.pullRight  = GameConsts.SLOPE_FEATURES.pullRight
        body.slopes.snapUp     = GameConsts.SLOPE_FEATURES.snapUp
        body.slopes.snapDown   = GameConsts.SLOPE_FEATURES.snapDown
        body.slopes.snapLeft   = GameConsts.SLOPE_FEATURES.snapLeft
        body.slopes.snapRight  = GameConsts.SLOPE_FEATURES.snapRight
    }, this)

GameConsts just in case

// Physics
    MAX_VELOCITY_X: 500,
    MAX_VELOCITY_Y: 1000, // Max velocity before player starts going through the ground.
    BULLET_GRAVITY: 850,

    // Slope Plugin
    SLOPE_FEATURES: {
        acceleration: 1500,
        bounceX: 0,
        bounceY: 0,
        debug: 0,
        dragX: 1000,
        dragY: 100,
        enableGravity: true,
        frictionX: 0,
        frictionY: 0,
        gravity: 1100,
        jump: 450,
        minimumOffsetY: 1,
        pullDown: 0,
        pullLeft: 0,
        pullRight: 0,
        pullUp: 0,
        snapDown: 0,
        snapLeft: 0,
        snapRight: 0,
        snapUp: 0
    },
@iCodeForBananas
Copy link
Author

ugh i figured this out while typing the issue...

        body.drag.x = 0
        body.drag.y = 0

@hexus
Copy link
Owner

hexus commented Sep 14, 2016

Yeah, be careful of drag, it rarely suits bullets! 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants