- Home /
Make object rotate about a circle with fixed velocity after collision
Hi, I am making a sort of gravitation field wherein, if you collide with an object say planet for example, you should start rotating around it, with a fixed velocity.
So, I have a ball (obviously, also circular). When the ball hits the planet, the ball should start rotating around it, with the velocity it hit the planet with.
Note: The ball is almost the size of the planet, approximately. Both are Equivalent of 0.2 World Coordinates on a screen height of 10, meaning they are 5% of screen height.
REQUIREMENT: 1. Ball has velocity V (Rigidbody2D, with mass 1 and circle collider 2d) 2. Planet is stationary (Just a circle collider 2d) 3. Once ball hits planet -> ball rotates around planet with velocity V infinitely
CURRENTLY WHAT HAPPENS Ball hits the planet and either STOPS completely, or just bounces back, depending on the angle of hit.
Please let me know how to implement this.
Currently, I have this script on the planet
void OnCollisionEnter2D(Collision2D other)
{
other.collider.rigidbody2D.velocity = (other.collider.rigidbody2D.velocity * 5)/other.collider.rigidbody2D.velocity.magnitude;
}
^Not really sure what this does, but I've written it and could use some clarity
Need a bit of help thanks.