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 motoko

Hi everybody, this is my first post!!

I have a puck and a paddle and i want to change the way the puck collides based on:

- The exact point (of the paddle surface) where the puck collides with the paddle.
- The velocity (dierction) of the paddle (if moving) while puck collides with it.

I'm trying to get the paddle properties within the puck "collideWith: function( other, axis )" method:

collideWith: function( other, axis ) {
	  ig.game.lastBX = this.vel.x;
	  ig.game.lastBY = this.last.y;
	  ig.game.lastPX = other.vel.x; //<other should be the paddle?
	  ig.game.lastPY = other.last.y; //<other should be the paddle?
}

But i get the same values for 'other' than for 'this' for vel and for position...

┬┐Some clue how should i apporach this?

1 decade ago by quidmonkey

An Entity's .last property is its last position. Whenever its update() is called, the first thing it does is assign its current position to .last and then proceed to update its current position.

Collision detection happens in game.checkEntities() which calls Entity.touches() which tests to see if an Entity overlaps another Entity. Impact does not have per pixel collision detection - you'll have to build it yourself; instead, it tests to see which axis the Entity collides on and passes that to you via collideWith().

For Pong, you really don't need per pixel collision detection, because the point will always be close to this.size.y / 2 - the midpoint along the y-axis on either x-end of the ball. Test for that.

You can tinker with the ball's vel by adding some fraction of the paddle's vel to it. This will simulate the paddle applying a pushing force to the ball.

1 decade ago by motoko

Thank you quidmonkey.

I had a mistake in the code that was drawing the debug values (in the main.js) on screen for the 'other' entity (copy/paste) :$, so i was always seeing same values for paddle and puck x,y... so geting the collide point was imposible if i were always getting the same values for both entities.

Now that i have noticed it i can get the exact collide point easy, as you wrote i only need the 'x' point. What i was now wondering is how to check wich type of entity is my puck colliding with becuase i only want the 'special' reaction when the puck clloides with the paddle. I have searched the Entity.js for a 'type' or a 'name' value to check with...

The paddle is always on the same pos.y and it's the only entity that is that 'pos.y' and i was thinking i could do it easy know if puck collides with paddle while checking the other.pos.y... but i don't like to do it so.

┬┐Some ideas?

1 decade ago by quidmonkey

In your puck.js you can do this:


collideWith: function( other, axis ){

     if( other instanceof EntityPaddle ){
          //do something
     }
}


You can also throw an AND on the if to test if axis == 'x-axis'.

1 decade ago by motoko

Thankyou very much, thats exactly what i was looking for!
Page 1 of 1
« first « previous next › last »