# foosball game - velocity problem

 0 Hello! 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. more ▼ asked Feb 09 '10 at 12:13 PM bOrange 27 ● 3 ● 4 ● 8 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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. more ▼ answered Feb 09 '10 at 04:33 PM Ashkan_gc 9.1k ● 33 ● 56 ● 117 hey! thanks for you help. What kind of join do you use? Why do you use join instead of normal parenting? Thanks Feb 10 '10 at 04:41 PM bOrange we use configurable joint that has just one axis rotation allowed arround the x axis and can just move along the x axis too. then we use springs to rotate it. it automatically rotate back to it's initial position and it has a really good gameplay. test it. Feb 10 '10 at 05:03 PM Ashkan_gc thanks a lot, really. sorry to bored but if you could me answer me just one more question. did you had any troubles when you move the bar horizontally and the player collides with the walls of the table? my start to jump, and i just have a box collider associated to the wall:S Feb 10 '10 at 07:12 PM bOrange add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x2503
x1879
x1371

asked: Feb 09 '10 at 12:13 PM

Seen: 1810 times

Last Updated: Feb 10 '10 at 03:06 PM