Skip to main content
Post Undeleted by Alexandre Borela
added 451 characters in body
Source Link

JustTo prevent the check of the object colliding against itself, just check the reference like so:

Core.objectCollision = function() {
    if (Core.Mouse.isHolding != null) {
        for (i in Core.Objects) {

            // Skip the object that was grabbed.
            if (i == Core.Mouse.isHolding)
                continue;

            if (isColliding(Core.Mouse.isHolding, Core.Objects[i])) {
                console.log("Colliding with world object!");
            }
        }
    }
}

just skip it inside yourNow, if you want to implement a physics engine, I really recommend you see this series https://www.youtube.com/watch?v=3Oay1YxkP5c even thou he implements a 3D engine, the core logic is the same.

Then, to get a better performance, you might want to look at quad trees so that objects that are far from each other are not checked for loopcollision, this: http://buildnewgames.com/gamephysics/ should give you some directions.

Just check the reference like so:

Core.objectCollision = function() {
    if (Core.Mouse.isHolding != null) {
        for (i in Core.Objects) {

            // Skip the object that was grabbed.
            if (i == Core.Mouse.isHolding)
                continue;

            if (isColliding(Core.Mouse.isHolding, Core.Objects[i])) {
                console.log("Colliding with world object!");
            }
        }
    }
}

just skip it inside your for loop.

To prevent the check of the object colliding against itself, just check the reference like so:

Core.objectCollision = function() {
    if (Core.Mouse.isHolding != null) {
        for (i in Core.Objects) {

            // Skip the object that was grabbed.
            if (i == Core.Mouse.isHolding)
                continue;

            if (isColliding(Core.Mouse.isHolding, Core.Objects[i])) {
                console.log("Colliding with world object!");
            }
        }
    }
}

Now, if you want to implement a physics engine, I really recommend you see this series https://www.youtube.com/watch?v=3Oay1YxkP5c even thou he implements a 3D engine, the core logic is the same.

Then, to get a better performance, you might want to look at quad trees so that objects that are far from each other are not checked for collision, this: http://buildnewgames.com/gamephysics/ should give you some directions.

Post Deleted by Alexandre Borela
Source Link

Just check the reference like so:

Core.objectCollision = function() {
    if (Core.Mouse.isHolding != null) {
        for (i in Core.Objects) {

            // Skip the object that was grabbed.
            if (i == Core.Mouse.isHolding)
                continue;

            if (isColliding(Core.Mouse.isHolding, Core.Objects[i])) {
                console.log("Colliding with world object!");
            }
        }
    }
}

just skip it inside your for loop.