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

minigame hitboxes too big? #89

Open
7yl4r opened this issue Apr 18, 2015 · 3 comments
Open

minigame hitboxes too big? #89

7yl4r opened this issue Apr 18, 2015 · 3 comments

Comments

@7yl4r
Copy link
Owner

7yl4r commented Apr 18, 2015

asteroid hitboxes, possible also the ship's, are way too big. You need a contoured mesh, not a circle/box around the asteroid and the ship. In some cases the ship was obviously nowhere near the asteroid they still collided

(from here)


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@7yl4r
Copy link
Owner Author

7yl4r commented Apr 21, 2015

To fix this is to use a json outline of the sprites as described in this tutorial. So something like:

vm.preload = function(){
    // stuff...
    // load the physics data json
    game.load.physics('asteroidPhysics', 'asteroid_physics.json');
    // more stuff..
}

// even more stuff...

vm.asteroid = vm.game.add.sprite(
        rnd(w*2/3.0, w*9/10.0),
        rnd(h/10.0, h*9/10.0),
        'a3');

// remove all of the current collision shapes from the physics body
vm.asteroid.body.clearShapes();

// load our polygon physics data
vm.asteroid.body.loadPolygon('asteroidPhysics', 'asteroid1');

first we need to get those .json files for the ship and the asteroids, and the recommended software is windows/mac exclusive (boo).

@7yl4r
Copy link
Owner Author

7yl4r commented Apr 24, 2015

possible file for p0.png: p0.json

@7yl4r
Copy link
Owner Author

7yl4r commented Apr 24, 2015

file format spec:

    { {% for body in bodies %}
        {% if not forloop.first %}, {% endif %}
        "{{body.name}}": [
            {% for fixture in body.fixtures %}{% if not forloop.first %} ,{% endif %}{% for polygon in fixture.polygons %}{% if not forloop.first %} ,{% endif %}
                {
                    "density": {{fixture.density}}, "friction": {{fixture.friction}}, "bounce": {{fixture.bounce}}, {% if fixture.isSensor %}"isSensor"=true, {% endif %}
                    "filter": { "categoryBits": {{fixture.filter_categoryBits}}, "maskBits": {{fixture.filter_maskBits}} },
                    "shape": [ {% for point in polygon %} {% if not forloop.first %}, {% endif %} {{point.x}}, {{point.y}} {% endfor %} ]
                } {% endfor %} {% endfor %}
        ]
        {% endfor %}
    }

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

No branches or pull requests

2 participants