none-9999 Posted August 27, 2014 Share Posted August 27, 2014 please i need know how make a circle collision (inelastic), exactly pool balls. note: without frameworks. Quote Link to comment Share on other sites More sharing options...
d13 Posted August 27, 2014 Share Posted August 27, 2014 For collision between two moving circles, you can use this function: https://gist.github.com/kittykatattack/befdddc4985a9a43bf68 If you have an array called `circles` full of circle objects, you can test them for collisions inside a game loop like this://Test for a collision inside a game loop:for (var i = 0; i < circles.length; i++) { //The first circle to use in the collision check var c1 = circles[i]; for (var j = i + 1; j < circles.length; j++) { //The second circle to use in the collision check var c2 = circles[j]; //Check for a collision and bounce the circles apart if //they collide. movingCircleCollision(c1, c2); }} Quote Link to comment Share on other sites More sharing options...
none-9999 Posted August 27, 2014 Author Share Posted August 27, 2014 For collision between two moving circles, you can use this function: https://gist.github.com/kittykatattack/befdddc4985a9a43bf68 If you have an array called `circles` full of circle objects, you can test them for collisions inside a game loop like this://Test for a collision inside a game loop:for (var i = 0; i < circles.length; i++) { //The first circle to use in the collision check var c1 = circles[i]; for (var j = i + 1; j < circles.length; j++) { //The second circle to use in the collision check var c2 = circles[j]; //Check for a collision and bounce the circles apart if //they collide. movingCircleCollision(c1, c2); }}ok, very thanks, i will test Quote Link to comment Share on other sites More sharing options...
Deban Posted August 27, 2014 Share Posted August 27, 2014 That code has a little problem that may or may not influence in your game (beside that if your are using "use strict" it will fail). It's that the order in which balls are checked for collision matters.For example if you have a line of balls: 0 1 2 3 45 6 7 8O-> OOOOOOOO If you check them in the same order that they are hitted, they will all move in one frame.(1 is hit so move to 2, 2 is hit so move to 3.......). But if it's checked in in the opposite each on will start to move one frame at a time.(8 was not hit, 7 was not hit....... 1 is hit so move to 2 ~ next frame: 8 was not hit.... 2 was hit so move to 3... ~ 7 frames later: 8 was hit so move) It also means that you can't collide with more that 1 ball per frame (because it will move you out of position). This could really make no difference at all in your game or it could make it feel a bit random, not always reacting at the same speed. Good luck with your game. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.