foosball game - velocity problem


I'm exploring unity and trying to develop a little game, something along the lines of a table football (foosball) game in the away it behaves.

The issue is when an object (in this case, a ball) hits the player object.

I'm using the following code attached to the ball collider.

 if(hit.gameObject.tag =="player") {

  var mag3=rigidbody.velocity.magnitude;
  rigidbody.AddForce(Vector3.Reflect(rigidbody.velocity*mag3,-Vector3.forward),        ForceMode.Impulse);


The ball is a rigidbody and the object player a boxcolider. So my doubt is how do i transfer the energy of the player (imagine that the player rotates 90 in one direction, and then quickly in the opposite direction, hitting the ball) to the ball, so that the ball velocity will be affected by the velocity of the player.

Thanks for any help, i trying to solve this problem to make it seems realistic but its have been a a little beat difficult to me.

If you are actually spinning the player object rigidbodies around, you shouldn't need to do any of the calculations of force and energy transfer yourself. This is what the physics engine is designed to do for you.

You should find that all you need to do is create and adjust the physics materials so that the collision results respond the way that you'd like them.

Is there any specific reason that you're trying to add some extra force in addition to the forces which occur as a natural result of the collision when the ball hits the player?


The problem may be that you have the player set as "Kinematic". Try turning that off, and use the physics engine to rotate it. You could do this either by applying torque, or by adding a configurable joint and setting the target angle.

For more information about using a configurable joint to control rotation, see this question and answer:

Keyboard Controlled Configurable Joint

we are making a foosball too. just create a normal rigidbody and attach a box collider to it and use a joint to connect it to the bar and then rotate it with forces and it should do what you want well.