Search Unity

Bouncing Object losing velocity

Discussion in 'Scripting' started by SergioD, Nov 13, 2010.

  1. SergioD

    SergioD

    Joined:
    Nov 13, 2010
    Posts:
    4
    Hello all!
    First of all, let me say i'm a complete beginner in both Unity and Scripting, and please, excuse me if i make mistakes writing in english :) .

    I've been doing some tutorials and now I'm learning C# in order to creat my own scripts.
    When i make some progress or learn something, i just try to apply it to Unity, and one of those "efforts" is a very simple Arkanoid game.

    Its' my second arkanoid clone, in the first one i managed speed and rebounds with code, in this one, i'm experimenting with Unity's physics.
    I just add velocity to the rigid body, apply a bouncy material and edit it to get rid of the friction.
    It works very well, with only one flaw. Sometimes...after a few collisions, it drops a lot of velocity (a few times to almost no speed at all).
    Sometimes the speed loss is very small, but still noticeable, and i even saw a few times that the ball would gain a lot of speed (out of nowhere).

    I saw a post here about a guy that was doing an "eternal bouncing ball" that had the same problem. His fix cannot be applied to mine, because the angles of the ball are constantly changing.

    What i do is this:

    Code (csharp):
    1.  public float ballSpeed = 8;
    2.      float xAngle = 5;
    3.      float yAngle = 5;
    And when i hit the space bar:

    HTML:
    void LaunchBall()
    	{
    		xAngle *= ballSpeed ;
    		yAngle *= ballSpeed ;
    		rigidbody.velocity =new Vector3 (xAngle, yAngle, 0);	
    	}
    I restrict the Z movement with a Configurable Joint, and after that...the ball bounces all the time, but as i tell you, sometimes it just don't work.

    So, making a long story short, i would love to know what can i do to fix this.
    I tried debugging the x and y angles, and are (of course) constantly changing and i can't figure out what step to do next.

    I'll appreciate any help from more experienced people (and i have the feeling i'll be asking for advice here a lot :p ).

    Thanks in advance!

    Cheers.

    Let me attach a test with that mechanic so you can see what i did wrong (I'm sorry some stuff like script names or folders are in spanish)
    View attachment $Arkanoid Napi.rar
     
    Last edited: Nov 13, 2010
  2. ksi

    ksi

    Joined:
    Jul 19, 2011
    Posts:
    3
    Hello,
    I know This answer is somewhat late (2010 - 2013) but I just encounterred the same issue and fixed it by
    1°) Launching the ball during the Start() (not very important here)
    2°) Defining and attaching the physical materia with the following attributes
    $unity_bounciness.png

    Attention this is still under UNITY V3.5 as I am planning to use my "won" Android License and they cannot be transferred to UNITY V4
    I hope that this "modest" first contribution will help.
     
  3. popeye1

    popeye1

    Joined:
    Dec 19, 2014
    Posts:
    28
    Had similar problem where my player dropped x-velocity when hitting floor. Added material ( friction: 0.001 bounciness: 0) to relevant floor colliders which solved problem. (friction = 0 gives you ice).