0
\$\begingroup\$

This question already has an answer here:

I have a collision in my game (see below) and a ball which is moving in a certainly speed to a random angle (x, y).

My problem is. If it touches the collision it should reflect.

enter image description here

I simply multiply the Y-value of my ball by -1 (negative 1), which works fine!

The main problem is my collision looks like this.

enter image description here

I made it like when the ball collides the red collider it should multiply reflect the y-value. If it collides the yellow collider it reflects x-value.

But... what happens when the ball coming from left to up (like on picture) and collides the red value. It just changes the y-value.

Maybe there's a way to make it easier, but I don't know it.

\$\endgroup\$

marked as duplicate by Gnemlock, DMGregory, Alexandre Vaillancourt, Josh May 12 '17 at 16:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    \$\begingroup\$ Could we see your collision code? Also, are you using LibGDX or Unity? You can't use both at the same time. \$\endgroup\$ – Charanor May 9 '17 at 17:36
  • \$\begingroup\$ I'm using libgdx. I don't have any code, this is my plan. How should it work, I just need a logic. \$\endgroup\$ – Eucar May 9 '17 at 18:11
  • \$\begingroup\$ Unfortunately, we're not a code writing service. And how do you know it's going to be a problem if you don't have any code? Try to implement your idea and if you get stuck come back and ask a specific question about your problem instead :) \$\endgroup\$ – Charanor May 9 '17 at 18:14
  • \$\begingroup\$ Thats the main problem. I don't know where to start. Should I create one collision or three colisions (up, right, bottom). \$\endgroup\$ – Eucar May 9 '17 at 18:22
  • 1
    \$\begingroup\$ You need to include the notion of normals in your collision handling. The red edge has a normal pointing upward. In the case that your ball is moving in the same direction as the normal (dot product of velocity and normal > 0), you should do nothing. \$\endgroup\$ – Drew Cummins May 9 '17 at 20:00
0
\$\begingroup\$

First of all, we need to clarify collision term; Collision is the "event" that happens when two colliders overlap each other, hence a ball cannot touch the collision, the ball's collider is touching the red collider in this case, and the "collision" occurs.

Secondly, since you did not provide any code and ask the question logically, the ball ignores the yellow collider here most probably. Check your collider settings and collision handling back again, or put the code here so anyone can provide a solution

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.