collision

2d html5 canvas collision, howto

给你一囗甜甜゛ 提交于 2019-11-28 11:51:25
As the title suggests, I am having trouble with object collision... I am currently working on a 2d Html5 canvas game using JavaScript. I know how to keep the "player" object from going outside the width/height of the game canvas, and i know how to do something when the player collides with an object (such as a power up or enemy or whatever) but i just don't know how to make a "solid" object meaning when the player hits the solid object, the player just stops, and cannot go through the solid object. This is what I have now (not all the code just what I feel is relevant, sorry if it's too much

JAVA elastic collision of moving and non moving circles

给你一囗甜甜゛ 提交于 2019-11-28 11:28:23
问题 I'm trying to write a java mobile application (J2ME) and I got stuck with a problem: in my project there are moving circles called shots, and non moving circles called orbs. When a shot hits an orb, it should bounce off by classical physical laws. However I couldn't find any algorithm of this sort. The movement of a shot is described by velocity on axis x and y (pixels/update). all the information about the circles is known: their location, radius and the speed (on axis x and y) of the shot.

Expected number of hash collisions

陌路散爱 提交于 2019-11-28 11:08:09
I feel like I'm way overthinking this problem, but here goes anyway... I have a hash table with M slots in its internal array. I need to insert N elements into the hash table. Assuming that I have a hash function that randomly inserts am element into a slot with equal probability for each slot, what's the expected value of the total number of hash collisions? (Sorry that this is more of a math question than a programming question). Edit: Here's some code I have to simulate it using Python. I'm getting numerical answers, but having trouble generalizing it to a formula and explaining it. import

How to detect collision but do not collide in box2d?

血红的双手。 提交于 2019-11-28 09:13:09
How to detect if body collides other body but do not react on this collision. By default i - detect collision and bodies collide. If i set fixtureDef filter - bodies do not collide but i can not detect collision. Help please! If the fixture never needs to collide with anything you could make it a sensor. If you need it to collide with some things but not others you could do contact->SetEnabled(false) in the PreSolve of the collision listener, depending on what it collided with. What you want here is a sensor fixture on a body. From the box2d manual: Sometimes game logic needs to know when two

Detect if line segment intersects square

别等时光非礼了梦想. 提交于 2019-11-28 08:28:53
问题 Anyone have a simple algorithm for this? No need for rotation or anything. Just finding if a line segment made from two points intersects a square 回答1: This code should do the trick. It checks where the line intersects the sides, then checks if that is within the width of the square. The number of intesections is returned. float CalcY(float xval, float x0, float y0, float x1, float y1) { if(x1 == x0) return NaN; return y0 + (xval - x0)*(y1 - y0)/(x1 - x0); } float CalcX(float yval, float x0,

Create vectors and collisions

北慕城南 提交于 2019-11-28 05:33:29
问题 I have a ball and a stick (for a billiard game). First the ball is placed in a position of a table. On clicking the ball the stick appears, in such a way that we can determine the angle by which stick is placed by clicking the ball (on clicking we determine the angle of mouse with respect to centre of ball and place the stick at that angle touching the ball). So now the stick is also in the table. Now I am dragging the stick along that angle only, if dragged in another angle than the initial

Gravity in pygame [closed]

点点圈 提交于 2019-11-28 01:59:07
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I'm making a platform game with pygame, and I would like to add gravity to it. Right now I only have a picture which moves when I

How to check intersection between a line and a rectangle?

让人想犯罪 __ 提交于 2019-11-28 00:11:06
问题 The title says it all, Ive been searching around and couldnt find anything that was straight and to the point. How would I take a line with points (x1,y1) & (x2, y2) and check its intersection between a rectangle (xR,yR)? I saw in the Line2D package that there were some intersection methods but not sure how to set it all up. Can someone show me a correct way of setting it up to check for an intersection (collision)? 回答1: Using the available classes from the 2D Graphics API. Rectangle r1 = new

How can i check if 2 controls overlap eachother on a canvas in WPF?

ε祈祈猫儿з 提交于 2019-11-27 23:50:32
问题 I am writing a designer that enables the user to drag controls around the screen. What would be the best way of detecting if a control is overlapping another control while i am dragging the one control around? Should i just get the dimensions of the FrameworkElement and keep on checking the dimensions of the other elements? Thanks. Eli 回答1: The dimension (FrameworkElement.ActualWidth FrameworkElement.ActualHeight) and postion (Canvas.Top, Canvas.Bottom,Canvas.Left, Canvas.Right) of your

How to fix circle and rectangle overlap in collision response?

心不动则不痛 提交于 2019-11-27 18:25:57
Since in the digital world a real collision almost never happens, we will always have a situation where the "colliding" circle overlaps the rectangle. How to put back the circle in the situation where it collides perfectly with the rectangle without overlap? Suppose that the rectangle is stopped (null velocity) and axis-aligned. I would solve this problem with a posteriori approach (in two dimensions). In short I have to solve this equation for t : Where: is a number that answers to the question: how many frames ago did the collision happen perfectly? is the radius of the circle. is the center