Real concept of Vector2.Reflect
so the bounce movement which i though would be pretty straight forward turned out to be a pain, as i am in the begging stages i want to learn how to use 2D vector2.reflect rather than using physics material for my ball bounce "LearnGame", All though i found lots of stuff about this in the internet don't feel like anyone explained how it would work for 2D well.
So for the real question i created this ball which moves toward a box and when it hits the box i want it to reflect and move accordingly . I don't this i understand the whole concept
![Example][1] [1]: /storage/temp/114810-t9br8.png
Please help me understand how it works for 2D or guide me to the right tutorial.
I tried to achieve this with below code but for some reason , when my ball hit the box, ball becomes flat as in the scale changes, don't understand it at all.
private void OnCollisionEnter2D(Collision2D collision)
{
Ray2D ray = new Ray2D(transform.position, transform.right);
Vector2 reflectDire = Vector2.Reflect(ray.direction, hit.normal);
float rot = 90 - Mathf.Atan2(reflectDire.y, reflectDire.x) * Mathf.Rad2Deg;
transform.eulerAngles = new Vector2(rot, 0);
}
Your answer
Follow this Question
Related Questions
Raycast2d does not always work properly 0 Answers
How can I detect which game object was clicked? 0 Answers
How to check if a 2D object is ahead of the player? 1 Answer
Rigidbody2D doesn't fall correctly when using MovePosition to move it horizontally 0 Answers
HELP! RigidBody2D position is acting incredibly goofy!! 0 Answers