1

I have a ball moving like this:

      ⚽
    ⭩ 
|‾‾‾‾‾‾|

Let's suppose its velocity is (-1, -1). When it collides with the ground, its velocity should be (-1,1), since it will keep going left but it will start going up (considering gravity is not necessary).

The normal vector of the collision is (0,1).

What happens is when I use Vector2.Reflect(velocity, normal), instead of returning (-1,1), it returns (1, -1).

What I want              What it returns

       ⚽                           ⚽  
    ⭦⭩                            ⭩
 |‾‾‾‾‾‾|                      |‾‾‾‾‾‾|
                                    ⭨

Seems like it's reflecting over the normal vector (1,0), but it is not. What am I doing wrong?

Daniel
  • 7,357
  • 7
  • 32
  • 84
  • PS: I've just solved it by rotating the normal vector 90º, but it seems like a workaround. – Daniel Jul 10 '19 at 05:34
  • https://stackoverflow.com/questions/41129573/unity-how-to-use-vector2-reflect look it – TimChang Jul 10 '19 at 05:38
  • I did exactly what the answers in the link say, the only difference is that the inDirection in my code is `collision.relativeVelocity`, where `collision` is the parameter of `OnCollisionEnter2D`, but I'm pretty sure this is not the problem. – Daniel Jul 10 '19 at 05:42
  • Do you print ` collision.relativeVelocity ` , What is this value? – TimChang Jul 10 '19 at 05:56
  • I'm guessing that the coordinate system you assume and the coordinate system being used aren't the same. For example, when you say, *`Let's suppose its velocity is (-1, -1)`* is that actually true in Unity, or did you just assume those values? – Draco18s no longer trusts SE Jul 10 '19 at 15:55
  • @TimChang the relativeVelocity is exactly what I said: (-1,-1). I'm supposing (-1,-1) but in Unity the real velocity is like (-0.5, -0.7). – Daniel Jul 10 '19 at 18:46
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error **and the shortest code necessary to reproduce it in the question itself**. Questions without a clear problem statement are not useful to other readers. See: [mcve] – Ruzihm Jul 10 '19 at 20:41

0 Answers0