[Help] Hovering Ball Not Reflecting Off Walls

Hello there, thx in advance.

I am working on a 3D game.

The intend: I want a Ball that is not affected by gravity but can still be manipulated by velocity(rigidbody). This ball is in a closed off room, but should bounce off the walls. If the ball hits a moving object, the moving objects velocity gets applied to the ball, there by increasing or decreasing its speed. This is why i don’t think it can work when its kinematic.

The problem: The ball can float in air quite welll, and i can move it at a speed using in FixedUpdate:

this.rigidbody.velocity = this.rigidbody.velocity.normalized * Time.deltaTime * 100.0f;

rigidbody.AddRelativeForce(100.0f * this.transform.forward);

But the ball just goes into an instant stop when hitting a wall, even though i should reflect its movement:
this code is triggered OnCollisionEnter,

this.rigidbody.velocity = Vector3.Reflect(this.rigidbody.velocity, contact.normal);

Can someone please explain what i am doing wrong?

Well If you are using rigidbody for the collision handling, there’s a big chance that the physical reaction happens before your code gets called - and if your physics materials have bounciness set to zero, the ball is already stopped when you try to reflect it.

There are two solutions. Decide whether you want to be using the physics of rigidbody or not.
Means either

  • use the physical collision reaction to bounce your ball (by using a proper physics material with bounciness).
  • use your own simulation (moving the ball in your code, using your own velocity variable while the rigidbody is set to kinematic (or not present at all)), detecting collisions on your own (using triggers perhaps, kinematic rigidbodies don’t produce regular collisions)

Hard to say which is better for you, since I don’t know what you are doing. But if you want your ball to interact with the rest of the physics world, then just go with the rigidbody.