- Home /
Problems with Bouncing
at the moment i have 4 low walls that square of an area, and these almost hockey puck ojbects that have bouncing physics that make then infinitely slide around and bounce off the 4 square walls. I also have the script that makes them bounce (adds force to push then into bouncing) which is this #pragma strict
function Start ()
{
var randomNumber = Random.Range(0,2);
if( randomNumber == 0)
{
rigidbody.AddForce (1000f, 0, 10000f);
}
if( randomNumber == 1)
{
rigidbody.AddForce (-5000f, 0, 10000f);
}
if( randomNumber == 2)
{
rigidbody.AddForce (7000f, 0, 10000f);
}
}
function Update () {
}
//JavaScript
//Randomly pushes the object in a certain direction
Right now when i start the game, they bounce off the walls infinitely and work perfectly find, until after a while one by one they will hit the wall and fly way over it. i'm not sure how this happens but is there any way that i can keep my object permanently grounded without raising its mass to slow it down?
Sounds like they are reaching such a high velocity from continual adding of force that they fly off(you are using very high force values in your code).
Why don't you just have your table with a $$anonymous$$inematic rigidbody on the table surface and one on each of the table sides. Then give the table surface rigidbody a very low friction "Physical $$anonymous$$aterial" (Ice) and each side a very high bounce "Physical $$anonymous$$aterial" rather than adding forces directly. This way you can give your puck a starting push and let the physics engine take care of the rest...
Why do you want it to carry of for infinity, puck's eventually slow down even on ice...
because i'm not actually making a table game like hockey or air hockey, i just meant the object i'm currently using looks like a hockey puck (placement for when i get real 3d characters). the game i'm making is a little hard to explain, but in the game there are lanes that the player runs through, and the player has to dodge the infinitely moving objects while the he runs through the lane.
As long as what I have suggested does not interfere with the rest of your game concept it is a better way of doing things. To keep the bouncing objects at a s$$anonymous$$dy speed you can check their current velocity magnitude, then add a little extra force in their current movement direction to top them up when needed.
You can give other objects their own physical materials which will mean they don't have to bounce and slide like the puck type movement objects do.
As long as the pucks remain at a constant speed that should be perfect. thanks, i'll try it!