Tuesday 15 January 2013

java - Strange Collision in LibGDX -


I'm trying to create a simple ball reflection on a block. I am using the libgdx framework.

I have problems with block collisions:

  public square world {public ball ball; Public times and times; Public block block; Public bounding box border, boundary, bound; Public world () {start (); } Public Zero Starter () {Ball = New Ball (10/2, 6); Bar = new bar (4,1); Block = new block (4,7); Boundblocks = new boundingbox (new vector 3 (block. Position.x, block.position.y, 0), new vector 3 (block position.x + 2, block.position.y + 1,0)); Bound = new bounding box (new vector 3 (ball.buzz.exe, ball.b.a., 0), new vector 3 (ball position. X + 1, ball.shomition.i + 1,0)); } Public Zune update (float delta) {ball.position.add (ball.direction.x * delta, ball.direction.y * delta, 0); // True collision if (ball.position.x + 0.25f> 9.65F) {ball.position.x = 9.65F - 0.25F; Ball.direction.x = -ball.feed; } // Top collision if (ball.position.y + 0.25f> 14.65F) {ball.position.y = 14.65f - 0.25F; Ball.direction.y = -ball.VELOCITY; } // Left Collision If (ball .position .x - 0.25F & lt; 0.35f) {ball.position.x = 0.35f + 0.25F; Ball.direction.x = Ball. VELOCITY; } // Bar collision if (ball.position.y & lt; 1 + 0.1 F) {if (ball.position.x> bar.position.x & amp; amp; amp; amp; ball.position.x & lt ; Bar.position.x + 2) {ball.position.y = 1+ 0.25F; Ball.direction.y = Ball. VELOCITY; }} // Block collision if (Boundblock canteens (boundball)) {ball.direction.x = -ball.valiti; Ball.direction.y = -ball.VELOCITY; }   

The problem starts with block collision It appears that it was "inside" in constant collision zone and it changes the direction of my ball all the time, The ball is brought into the "step" in the block.

All suggestions are welcome!

Thank you very much for your help!

The problem is that you should never bound toBall Do not update, so it always assumes that it is embedded in the boundblock .

No comments:

Post a Comment