7yl4r / the-oregon-trajectory

:rocket: The Oregon Trail -- in SPAAACE!
http://7yl4r.github.io/the-oregon-trajectory/
GNU Affero General Public License v3.0
17 stars 6 forks source link

minigame hitboxes too big? #89

Open 7yl4r opened 9 years ago

7yl4r commented 9 years ago

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!](https://www.bountysource.com/issues/11450874-minigame-hitboxes-too-big?utm_campaign=plugin&utm_content=tracker%2F13859664&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F13859664&utm_medium=issues&utm_source=github).
7yl4r commented 9 years ago

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 commented 9 years ago

possible file for p0.png: p0.json

7yl4r commented 9 years ago

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 %}
    }