1
\$\begingroup\$

I have a circle with a RigidBody2D and CircleCollider2D components on it.

I'm trying to make it move constantly inside a bigger circle without gravity involved, make it bounce off the circle walls like it has constant velocity but without any delays, same speed all the time.

Here is an example of the same behaviour but inside a rectangle: enter image description here

I would like to do the same but inside a circle and detect the collision with the circle walls

Thanks in advance :)

\$\endgroup\$
1
  • \$\begingroup\$ I'm trying to change the transform position until I reach a destination point and then take another random point on the circle and get to it, But it's not a physics based solution, I want it to bounce out of the circle walls like a real physics collision, not to a random position \$\endgroup\$
    – AfikDeri
    Commented Mar 9, 2018 at 10:56

1 Answer 1

1
\$\begingroup\$

Some suggestions to get you started:

  1. Change your rigidbody gravity scale to 0 and mass to 0.
  2. Rigidbody2D.AddForce();
  3. Use the EdgeCollider component for your shape you want to bounce off.

Good luck

\$\endgroup\$
4
  • \$\begingroup\$ Thanks for the reply, this is not the answer, I already have my mass at 0 and gravity at 0, the thing with AddForce() is not clear to me, when to add force? how match? on Start? Every update? \$\endgroup\$
    – AfikDeri
    Commented Mar 9, 2018 at 15:49
  • \$\begingroup\$ You only have to AddForce once, if your object has no mass, gravity or drag. It should bounce around forever. Look at physics materials for your collider on your moving object too, then you can control its bounciness for e.g. \$\endgroup\$
    – Nilmag
    Commented Mar 9, 2018 at 16:01
  • \$\begingroup\$ It works, I've created a new Physics Material 2D named Bouncy with a friction of 0 and bounciness of 1 and added it to the ball, it now works great. Thanks \$\endgroup\$
    – AfikDeri
    Commented Mar 9, 2018 at 16:25
  • 2
    \$\begingroup\$ I'd recommend keeping some mass on the object, otherwise force calculations get a bit weird (acceleration = force / mass which approaches infinity as mass approaches zero). Mass itself won't slow the object down (quite the opposite - inertia due to mass resists slowing down) as long as you've turned off the drag. \$\endgroup\$
    – DMGregory
    Commented Mar 9, 2018 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .