Collision detection & resolution: circle in a playfield of other circles and polygons











up vote
1
down vote

favorite
1












I am working on a game that has a player sprite surrounded by a collision circle of a known radius. The player sprite can move about a playfield that consists of other sprites with their own collision circles and other obstacles made up of polygons. The other obstacles are rectangles at a 45 degree angle.



Playfield example



In addition, I want the player to adjust its movement when it does collide. I want the player to try to "push through" past the object instead of being stopped by it.



For example, if the player were to collide with another sprite's bounding circle, it would be stopped if its vector was exactly perpendicular to the tangent of the two circles' intersection.



Perpendicular tangent example



However, if not perfectly perpendicular, the player would be, slowly at first, then faster, pushed along the tangent of the circle until it can continue past it unimpeded.



Edging around a circle example



This works similarly when encountering one of the 45 degree rectangles.



Edging around a rectangle example



What I need help with is the following: I am trying to find an analytic solution to detect both other sprites and obsticles, have the player's movement adjusted, and possibly stopped when adjusted to wedge between two or more objects.



Trapped by a circle and a rectangle example



I can do the collision detection and deflection for one object type at a time, but am struggling to put everything together into a comprehensive algorithm. I am currently working on an iterative pairwise resolution approach that "tries" different locations to result in a best-guess solution, but I really want a mathematically analytic solution. I'm hoping to have a function something like what appears in this psuedocode.



x = [player's x location]
y = [player's y location]
r = [player's collision radius]

// Array of other sprites on the playfield,
spr = [other sprites array]
// which contains 3 parameters, x, y, r. E.g., spr[3].x or spr[3].r,
// for the x position or collision radius for the fourth sprite in the
// array.

// Array of 45 degree rectangles on the playfield,
rect = [array of rectangles]
// which contain 4 parameters, x1, y1, x2, y2, the two opposite points
// of the rectangle. E.g., rect[0].x1, for the x position of the first
// point of the first rectangle.

// For simplicity, assume the above variables are all directly accessable
// in the function below.

// requestX and requestY is the position to which the player would
// like to move the player sprite.
definefunction collisionAdjustor(requestX, requestY) {

// Here I'd like to adjust the requested position if needed because
// of an intersection with one or more other sprites or rectangles.

// Finally return the location at which the player will actually be
// arriving.
return destinationX, destinationY
}


Any advice or suggestions would be much appreciated.



--Richard










share|improve this question
























  • I deleted my answer to encourage more detailed answers. I would suggest to mention your current approach in the question (iterative pairwise resolution) and that you are looking for an analytic solution. I would also put more focus on the multi-obstacle case as you seem to have solved the single-obstacle case.
    – Nico Schertler
    Nov 1 at 18:08










  • Thanks. I improved the question and added in some psuedocode to give a sense of what I'm looking for.
    – Richard Ellwood
    Nov 21 at 2:10















up vote
1
down vote

favorite
1












I am working on a game that has a player sprite surrounded by a collision circle of a known radius. The player sprite can move about a playfield that consists of other sprites with their own collision circles and other obstacles made up of polygons. The other obstacles are rectangles at a 45 degree angle.



Playfield example



In addition, I want the player to adjust its movement when it does collide. I want the player to try to "push through" past the object instead of being stopped by it.



For example, if the player were to collide with another sprite's bounding circle, it would be stopped if its vector was exactly perpendicular to the tangent of the two circles' intersection.



Perpendicular tangent example



However, if not perfectly perpendicular, the player would be, slowly at first, then faster, pushed along the tangent of the circle until it can continue past it unimpeded.



Edging around a circle example



This works similarly when encountering one of the 45 degree rectangles.



Edging around a rectangle example



What I need help with is the following: I am trying to find an analytic solution to detect both other sprites and obsticles, have the player's movement adjusted, and possibly stopped when adjusted to wedge between two or more objects.



Trapped by a circle and a rectangle example



I can do the collision detection and deflection for one object type at a time, but am struggling to put everything together into a comprehensive algorithm. I am currently working on an iterative pairwise resolution approach that "tries" different locations to result in a best-guess solution, but I really want a mathematically analytic solution. I'm hoping to have a function something like what appears in this psuedocode.



x = [player's x location]
y = [player's y location]
r = [player's collision radius]

// Array of other sprites on the playfield,
spr = [other sprites array]
// which contains 3 parameters, x, y, r. E.g., spr[3].x or spr[3].r,
// for the x position or collision radius for the fourth sprite in the
// array.

// Array of 45 degree rectangles on the playfield,
rect = [array of rectangles]
// which contain 4 parameters, x1, y1, x2, y2, the two opposite points
// of the rectangle. E.g., rect[0].x1, for the x position of the first
// point of the first rectangle.

// For simplicity, assume the above variables are all directly accessable
// in the function below.

// requestX and requestY is the position to which the player would
// like to move the player sprite.
definefunction collisionAdjustor(requestX, requestY) {

// Here I'd like to adjust the requested position if needed because
// of an intersection with one or more other sprites or rectangles.

// Finally return the location at which the player will actually be
// arriving.
return destinationX, destinationY
}


Any advice or suggestions would be much appreciated.



--Richard










share|improve this question
























  • I deleted my answer to encourage more detailed answers. I would suggest to mention your current approach in the question (iterative pairwise resolution) and that you are looking for an analytic solution. I would also put more focus on the multi-obstacle case as you seem to have solved the single-obstacle case.
    – Nico Schertler
    Nov 1 at 18:08










  • Thanks. I improved the question and added in some psuedocode to give a sense of what I'm looking for.
    – Richard Ellwood
    Nov 21 at 2:10













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I am working on a game that has a player sprite surrounded by a collision circle of a known radius. The player sprite can move about a playfield that consists of other sprites with their own collision circles and other obstacles made up of polygons. The other obstacles are rectangles at a 45 degree angle.



Playfield example



In addition, I want the player to adjust its movement when it does collide. I want the player to try to "push through" past the object instead of being stopped by it.



For example, if the player were to collide with another sprite's bounding circle, it would be stopped if its vector was exactly perpendicular to the tangent of the two circles' intersection.



Perpendicular tangent example



However, if not perfectly perpendicular, the player would be, slowly at first, then faster, pushed along the tangent of the circle until it can continue past it unimpeded.



Edging around a circle example



This works similarly when encountering one of the 45 degree rectangles.



Edging around a rectangle example



What I need help with is the following: I am trying to find an analytic solution to detect both other sprites and obsticles, have the player's movement adjusted, and possibly stopped when adjusted to wedge between two or more objects.



Trapped by a circle and a rectangle example



I can do the collision detection and deflection for one object type at a time, but am struggling to put everything together into a comprehensive algorithm. I am currently working on an iterative pairwise resolution approach that "tries" different locations to result in a best-guess solution, but I really want a mathematically analytic solution. I'm hoping to have a function something like what appears in this psuedocode.



x = [player's x location]
y = [player's y location]
r = [player's collision radius]

// Array of other sprites on the playfield,
spr = [other sprites array]
// which contains 3 parameters, x, y, r. E.g., spr[3].x or spr[3].r,
// for the x position or collision radius for the fourth sprite in the
// array.

// Array of 45 degree rectangles on the playfield,
rect = [array of rectangles]
// which contain 4 parameters, x1, y1, x2, y2, the two opposite points
// of the rectangle. E.g., rect[0].x1, for the x position of the first
// point of the first rectangle.

// For simplicity, assume the above variables are all directly accessable
// in the function below.

// requestX and requestY is the position to which the player would
// like to move the player sprite.
definefunction collisionAdjustor(requestX, requestY) {

// Here I'd like to adjust the requested position if needed because
// of an intersection with one or more other sprites or rectangles.

// Finally return the location at which the player will actually be
// arriving.
return destinationX, destinationY
}


Any advice or suggestions would be much appreciated.



--Richard










share|improve this question















I am working on a game that has a player sprite surrounded by a collision circle of a known radius. The player sprite can move about a playfield that consists of other sprites with their own collision circles and other obstacles made up of polygons. The other obstacles are rectangles at a 45 degree angle.



Playfield example



In addition, I want the player to adjust its movement when it does collide. I want the player to try to "push through" past the object instead of being stopped by it.



For example, if the player were to collide with another sprite's bounding circle, it would be stopped if its vector was exactly perpendicular to the tangent of the two circles' intersection.



Perpendicular tangent example



However, if not perfectly perpendicular, the player would be, slowly at first, then faster, pushed along the tangent of the circle until it can continue past it unimpeded.



Edging around a circle example



This works similarly when encountering one of the 45 degree rectangles.



Edging around a rectangle example



What I need help with is the following: I am trying to find an analytic solution to detect both other sprites and obsticles, have the player's movement adjusted, and possibly stopped when adjusted to wedge between two or more objects.



Trapped by a circle and a rectangle example



I can do the collision detection and deflection for one object type at a time, but am struggling to put everything together into a comprehensive algorithm. I am currently working on an iterative pairwise resolution approach that "tries" different locations to result in a best-guess solution, but I really want a mathematically analytic solution. I'm hoping to have a function something like what appears in this psuedocode.



x = [player's x location]
y = [player's y location]
r = [player's collision radius]

// Array of other sprites on the playfield,
spr = [other sprites array]
// which contains 3 parameters, x, y, r. E.g., spr[3].x or spr[3].r,
// for the x position or collision radius for the fourth sprite in the
// array.

// Array of 45 degree rectangles on the playfield,
rect = [array of rectangles]
// which contain 4 parameters, x1, y1, x2, y2, the two opposite points
// of the rectangle. E.g., rect[0].x1, for the x position of the first
// point of the first rectangle.

// For simplicity, assume the above variables are all directly accessable
// in the function below.

// requestX and requestY is the position to which the player would
// like to move the player sprite.
definefunction collisionAdjustor(requestX, requestY) {

// Here I'd like to adjust the requested position if needed because
// of an intersection with one or more other sprites or rectangles.

// Finally return the location at which the player will actually be
// arriving.
return destinationX, destinationY
}


Any advice or suggestions would be much appreciated.



--Richard







geometry game-physics trigonometry






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 2:03

























asked Oct 30 at 2:36









Richard Ellwood

447




447












  • I deleted my answer to encourage more detailed answers. I would suggest to mention your current approach in the question (iterative pairwise resolution) and that you are looking for an analytic solution. I would also put more focus on the multi-obstacle case as you seem to have solved the single-obstacle case.
    – Nico Schertler
    Nov 1 at 18:08










  • Thanks. I improved the question and added in some psuedocode to give a sense of what I'm looking for.
    – Richard Ellwood
    Nov 21 at 2:10


















  • I deleted my answer to encourage more detailed answers. I would suggest to mention your current approach in the question (iterative pairwise resolution) and that you are looking for an analytic solution. I would also put more focus on the multi-obstacle case as you seem to have solved the single-obstacle case.
    – Nico Schertler
    Nov 1 at 18:08










  • Thanks. I improved the question and added in some psuedocode to give a sense of what I'm looking for.
    – Richard Ellwood
    Nov 21 at 2:10
















I deleted my answer to encourage more detailed answers. I would suggest to mention your current approach in the question (iterative pairwise resolution) and that you are looking for an analytic solution. I would also put more focus on the multi-obstacle case as you seem to have solved the single-obstacle case.
– Nico Schertler
Nov 1 at 18:08




I deleted my answer to encourage more detailed answers. I would suggest to mention your current approach in the question (iterative pairwise resolution) and that you are looking for an analytic solution. I would also put more focus on the multi-obstacle case as you seem to have solved the single-obstacle case.
– Nico Schertler
Nov 1 at 18:08












Thanks. I improved the question and added in some psuedocode to give a sense of what I'm looking for.
– Richard Ellwood
Nov 21 at 2:10




Thanks. I improved the question and added in some psuedocode to give a sense of what I'm looking for.
– Richard Ellwood
Nov 21 at 2:10

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53056603%2fcollision-detection-resolution-circle-in-a-playfield-of-other-circles-and-pol%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53056603%2fcollision-detection-resolution-circle-in-a-playfield-of-other-circles-and-pol%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...