Skip to main content
Added explanation of how to find contact points
Source Link
  1. My suggestion to accomplish this would be to adjust the collision normal accordingly. You could have one normal at the top corner pointing, say 45 deg, up/right and one normal in the bottom corner pointing down/right. For any collision between these you can interpolate between these two normals (using Vector2.Lerp) to get an angle that will then point stright to the right in the exact middle of the edge. In case you want a region with perfect horizontal bounce you can use two normals on the borders of this region pointing in the horizontal direction.

  2. You can handle this by using different normals for different edges.

3 and 4. You are on the right track. In the future you can implement a sweep and prune algorithm to determine for which entities to make the broad phase collision detect. For your purpose there is no need for it right now as you only need to check the ball against all other entities which is a O(n) operation. If you have many moving entities which may hit each other you might need it as check all these against each other will be a O(m^2) operation (m number of moving entities that can hit each other)

EDIT: Note that when interpolating two unitvectors you are not guaranteed to get a unit vector back, it will probably be a little shorter. So make sure to normalize after interpolation.

EDIT 2: If you are interpolating along the vertical side then you want your amount to be zero when at the top and one at the bottom. This should depend on the y-value of the contact point.

float amount = (contact.Point.Y - top.Y) / (bottom.Y - top.Y);

Assuming that y is positive in the downwards direction (bottom.Y > top.Y). This will give a value for amount that is in the range of [0..1]

EDIT 3: To find correct contact points you will have two cases to handle. For ball-edge contact follow the reverse axis of collision (which is the edge normal) from the center of ball to the edge of the ball. That will be your contact point. You might have some overlapping due to movement from last frame and this can be handled by a special interpenetration handling method before handleing the collision. Remember to check if you actually have a closing velocity along the axis before handling collision or you might experience some very strange behaviour.

To find contact point for ball-vertex contact do the same thing but the axis in this case is the vecetor from the vertex to the ball center.

  1. My suggestion to accomplish this would be to adjust the collision normal accordingly. You could have one normal at the top corner pointing, say 45 deg, up/right and one normal in the bottom corner pointing down/right. For any collision between these you can interpolate between these two normals (using Vector2.Lerp) to get an angle that will then point stright to the right in the exact middle of the edge. In case you want a region with perfect horizontal bounce you can use two normals on the borders of this region pointing in the horizontal direction.

  2. You can handle this by using different normals for different edges.

3 and 4. You are on the right track. In the future you can implement a sweep and prune algorithm to determine for which entities to make the broad phase collision detect. For your purpose there is no need for it right now as you only need to check the ball against all other entities which is a O(n) operation. If you have many moving entities which may hit each other you might need it as check all these against each other will be a O(m^2) operation (m number of moving entities that can hit each other)

EDIT: Note that when interpolating two unitvectors you are not guaranteed to get a unit vector back, it will probably be a little shorter. So make sure to normalize after interpolation.

EDIT 2: If you are interpolating along the vertical side then you want your amount to be zero when at the top and one at the bottom. This should depend on the y-value of the contact point.

float amount = (contact.Point.Y - top.Y) / (bottom.Y - top.Y);

Assuming that y is positive in the downwards direction (bottom.Y > top.Y). This will give a value for amount that is in the range of [0..1]

  1. My suggestion to accomplish this would be to adjust the collision normal accordingly. You could have one normal at the top corner pointing, say 45 deg, up/right and one normal in the bottom corner pointing down/right. For any collision between these you can interpolate between these two normals (using Vector2.Lerp) to get an angle that will then point stright to the right in the exact middle of the edge. In case you want a region with perfect horizontal bounce you can use two normals on the borders of this region pointing in the horizontal direction.

  2. You can handle this by using different normals for different edges.

3 and 4. You are on the right track. In the future you can implement a sweep and prune algorithm to determine for which entities to make the broad phase collision detect. For your purpose there is no need for it right now as you only need to check the ball against all other entities which is a O(n) operation. If you have many moving entities which may hit each other you might need it as check all these against each other will be a O(m^2) operation (m number of moving entities that can hit each other)

EDIT: Note that when interpolating two unitvectors you are not guaranteed to get a unit vector back, it will probably be a little shorter. So make sure to normalize after interpolation.

EDIT 2: If you are interpolating along the vertical side then you want your amount to be zero when at the top and one at the bottom. This should depend on the y-value of the contact point.

float amount = (contact.Point.Y - top.Y) / (bottom.Y - top.Y);

Assuming that y is positive in the downwards direction (bottom.Y > top.Y). This will give a value for amount that is in the range of [0..1]

EDIT 3: To find correct contact points you will have two cases to handle. For ball-edge contact follow the reverse axis of collision (which is the edge normal) from the center of ball to the edge of the ball. That will be your contact point. You might have some overlapping due to movement from last frame and this can be handled by a special interpenetration handling method before handleing the collision. Remember to check if you actually have a closing velocity along the axis before handling collision or you might experience some very strange behaviour.

To find contact point for ball-vertex contact do the same thing but the axis in this case is the vecetor from the vertex to the ball center.

added 408 characters in body
Source Link
  1. My suggestion to accomplish this would be to adjust the collision normal accordingly. You could have one normal at the top corner pointing, say 45 deg, up/right and one normal in the bottom corner pointing down/right. For any collision between these you can interpolate between these two normals (using Vector2.Lerp) to get an angle that will then point stright to the right in the exact middle of the edge. In case you want a region with perfect horizontal bounce you can use two normals on the borders of this region pointing in the horizontal direction.

  2. You can handle this by using different normals for different edges.

3 and 4. You are on the right track. In the future you can implement a sweep and prune algorithm to determine for which entities to make the broad phase collision detect. For your purpose there is no need for it right now as you only need to check the ball against all other entities which is a O(n) operation. If you have many moving entities which may hit each other you might need it as check all these against each other will be a O(m^2) operation (m number of moving entities that can hit each other)

EDIT: Note that when interpolating two unitvectors you are not guaranteed to get a unit vector back, it will probably be a little shorter. So make sure to normalize after interpolation.

EDIT 2: If you are interpolating along the vertical side then you want your amount to be zero when at the top and one at the bottom. This should depend on the y-value of the contact point.

float amount = (contact.Point.Y - top.Y) / (bottom.Y - top.Y);

Assuming that y is positive in the downwards direction (bottom.Y > top.Y). This will give a value for amount that is in the range of [0..1]

  1. My suggestion to accomplish this would be to adjust the collision normal accordingly. You could have one normal at the top corner pointing, say 45 deg, up/right and one normal in the bottom corner pointing down/right. For any collision between these you can interpolate between these two normals (using Vector2.Lerp) to get an angle that will then point stright to the right in the exact middle of the edge. In case you want a region with perfect horizontal bounce you can use two normals on the borders of this region pointing in the horizontal direction.

  2. You can handle this by using different normals for different edges.

3 and 4. You are on the right track. In the future you can implement a sweep and prune algorithm to determine for which entities to make the broad phase collision detect. For your purpose there is no need for it right now as you only need to check the ball against all other entities which is a O(n) operation. If you have many moving entities which may hit each other you might need it as check all these against each other will be a O(m^2) operation (m number of moving entities that can hit each other)

EDIT: Note that when interpolating two unitvectors you are not guaranteed to get a unit vector back, it will probably be a little shorter. So make sure to normalize after interpolation.

  1. My suggestion to accomplish this would be to adjust the collision normal accordingly. You could have one normal at the top corner pointing, say 45 deg, up/right and one normal in the bottom corner pointing down/right. For any collision between these you can interpolate between these two normals (using Vector2.Lerp) to get an angle that will then point stright to the right in the exact middle of the edge. In case you want a region with perfect horizontal bounce you can use two normals on the borders of this region pointing in the horizontal direction.

  2. You can handle this by using different normals for different edges.

3 and 4. You are on the right track. In the future you can implement a sweep and prune algorithm to determine for which entities to make the broad phase collision detect. For your purpose there is no need for it right now as you only need to check the ball against all other entities which is a O(n) operation. If you have many moving entities which may hit each other you might need it as check all these against each other will be a O(m^2) operation (m number of moving entities that can hit each other)

EDIT: Note that when interpolating two unitvectors you are not guaranteed to get a unit vector back, it will probably be a little shorter. So make sure to normalize after interpolation.

EDIT 2: If you are interpolating along the vertical side then you want your amount to be zero when at the top and one at the bottom. This should depend on the y-value of the contact point.

float amount = (contact.Point.Y - top.Y) / (bottom.Y - top.Y);

Assuming that y is positive in the downwards direction (bottom.Y > top.Y). This will give a value for amount that is in the range of [0..1]

Added normalization after interploation
Source Link
  1. My suggestion to accomplish this would be to adjust the collision normal accordingly. You could have one normal at the top corner pointing, say 45 deg, up/right and one normal in the bottom corner pointing down/right. For any collision between these you can interpolate between these two normals (using Vector2.Lerp) to get an angle that will then point stright to the right in the exact middle of the edge. In case you want a region with perfect horizontal bounce you can use two normals on the borders of this region pointing in the horizontal direction.

  2. You can handle this by using different normals for different edges.

3 and 4. You are on the right track. In the future you can implement a sweep and prune algorithm to determine for which entities to make the broad phase collision detect. For your purpose there is no need for it right now as you only need to check the ball against all other entities which is a O(n) operation. If you have many moving entities which may hit each other you might need it as check all these against each other will be a O(m^2) operation (m number of moving entities that can hit each other)

EDIT: Note that when interpolating two unitvectors you are not guaranteed to get a unit vector back, it will probably be a little shorter. So make sure to normalize after interpolation.

  1. My suggestion to accomplish this would be to adjust the collision normal accordingly. You could have one normal at the top corner pointing, say 45 deg, up/right and one normal in the bottom corner pointing down/right. For any collision between these you can interpolate between these two normals (using Vector2.Lerp) to get an angle that will then point stright to the right in the exact middle of the edge. In case you want a region with perfect horizontal bounce you can use two normals on the borders of this region pointing in the horizontal direction.

  2. You can handle this by using different normals for different edges.

3 and 4. You are on the right track. In the future you can implement a sweep and prune algorithm to determine for which entities to make the broad phase collision detect. For your purpose there is no need for it right now as you only need to check the ball against all other entities which is a O(n) operation. If you have many moving entities which may hit each other you might need it as check all these against each other will be a O(m^2) operation (m number of moving entities that can hit each other)

  1. My suggestion to accomplish this would be to adjust the collision normal accordingly. You could have one normal at the top corner pointing, say 45 deg, up/right and one normal in the bottom corner pointing down/right. For any collision between these you can interpolate between these two normals (using Vector2.Lerp) to get an angle that will then point stright to the right in the exact middle of the edge. In case you want a region with perfect horizontal bounce you can use two normals on the borders of this region pointing in the horizontal direction.

  2. You can handle this by using different normals for different edges.

3 and 4. You are on the right track. In the future you can implement a sweep and prune algorithm to determine for which entities to make the broad phase collision detect. For your purpose there is no need for it right now as you only need to check the ball against all other entities which is a O(n) operation. If you have many moving entities which may hit each other you might need it as check all these against each other will be a O(m^2) operation (m number of moving entities that can hit each other)

EDIT: Note that when interpolating two unitvectors you are not guaranteed to get a unit vector back, it will probably be a little shorter. So make sure to normalize after interpolation.

Source Link
Loading