Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Silent

Hello.
I'm making a breakout game, and I need to handle ball-brick collision. I need it to kill the other entity if it's a brick, and in either case invert it's vel.y. It sounds pretty straigt forward:

collideWith: function (other) {

    if(other.type === ig.Entity.TYPE.B) {
        other.kill();
    }

    this.vel.y = -this.vel.y;
}

However, it doesn't work as expected. For some reason, whenever my ball hits another entity, it loses it's vel.y. Can someone give me a hand?

Thanks in advance :)

1 decade ago by Joncom

Perhaps try making ball.collides == ig.Entity.COLLIDES.FIXED so that its velocity cannot be changed by other entities. It sounds like right now that may be happening.

1 decade ago by Silent

No, it doesn't work. Both the brick and the board are fixed. The ball was lite, now it's fixed. Same result.

1 decade ago by Joncom

On second thought, why not set .collides == ig.Entity.COLLIDES.NONE for both the bricks and the ball?

This will prevent them from "pushing" on each other altogether and let you handle collisions however you choose.

Obviously collision-resolving is getting in the way. Why is it on to begin with?

Edit: Or, if for some reason you must leave colliding enabled, maybe keep track of x and y velocities in a new variable, so that on collision, you can flip the direction and resume velocity.

1 decade ago by Silent

Thanks, I will try this tomorrow as soon as I get home.

I'm not sure what you mean by "Why is it on to begin with?". I need to resolve collision on order to know when is the ball touching a brick/board for it to bounce off.

Also, according to the class reference, .collides can be never, lite, passive, active or fixed. As far as I can see it can't be none.

1 decade ago by Joncom

The problem is that you want to use collideWith, and that&039;s fine, except when you use #.collides == ig.Entity.COLLIDES.FIXED fixed for both the blocks and the ball. This is because both are equal and thus they will collide and slow each other down.

Keep things as you already have them, but set .collides == ig.Entity.COLLIDES.ACTIVE or something other than fixed for the blocks! The point is, you do NOT want your ball to be moved by the blocks.

Then when a collideWith event is called in your ball entity, reverse direction. Since the blocks are now "weaker" than the ball, your ball will not lose any velocity to it.

I need to resolve collision on order to know when is the ball touching a brick/board for it to bounce off.
Not true. You can turn off .collides and still use .checkAgainst and the .check to monitor collisions.

1 decade ago by Silent

Well, if I turn off collision completely, it seems to bounce off the board just fine - but it doesn't always work for the blocks. Sometimes it does, sometimes it doesn't.

If I set it to active, both entities move. This is not what I want.

1 decade ago by Joncom

Quote from Silent
If I set it to active, both entities move. This is not what I want.
Hmm. Try PASSIVE then. That should prevent blocks from moving the ball for sure.

1 decade ago by Silent

Passive and Lite don't collide. Why does it hate me so much? Someone PLEASE help me. I'm so frustrated.

EDIT:
I solved it!
It turns out the way to make an entity to bounce back is, believe it or not, set .bounciness to 1.

Success! :)
Page 1 of 1
« first « previous next › last »