Bounce ball issues help

I am creating a game where the ball needs to bounce inside a box like in ping pong game.

The problem is: after a few bounces, the ball seems to stabilize and bounce back and forth at the same place.
It seems like the ball is "square".

I already searched the forum and google for a solution but got none, except to make collision shape "circle", but that did not solve the issue.

The ball image is transparent square. Is this the problem? If so, how can I make its image round, without any transparent square borders?

Any help is appreciated, thanks.

Comments

  • Jogos_TDAJogos_TDA PRO Posts: 46
    ANyone?
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Hi @Jogos_TDA, it sounds like you'll need to check for the balls linear velocity Y (if it's getting stuck side to side). When that equals 0, it is just moving side to side with no angle, then give it some angle when it bounces off something. You would do this for the X direction if its getting stuck up and down.

    That's the general idea, but obviously not specific code. Hope it helps.
  • ericzingelerericzingeler Member Posts: 334
    @Jogos_TDA

    Can you post a screenshot of your movement & physics attributes?
  • Jogos_TDAJogos_TDA PRO Posts: 46
    It is getting stuck sometimes vertical and sometimes horizontal... :((
    Here is a video to illustrate what happens:

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited May 2013
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Here is a little sample project. Press the space bar and the paddle will shoot a ball going directly across the screen (so it should get stuck side to side) but the ball actor has a rule on it to correct that bounce and send it off at an angle if it's linear.velocity.y = 0. Check it out.
  • Jogos_TDAJogos_TDA PRO Posts: 46
    Here is a little sample project. Press the space bar and the paddle will shoot a ball going directly across the screen (so it should get stuck side to side) but the ball actor has a rule on it to correct that bounce and send it off at an angle if it's linear.velocity.y = 0. Check it out.
    Good idea.
    I am checking it now, but in your code example the ball is getting stuck also...
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    side to side? Thats the only direction I wrote anything for, I didn't touch the top to bottom.
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited May 2013
    Yeah I see, sometimes it still would get stuck. Try changing the random number that are now (-45,45) to something like (60,80). It's really meant just to illustrate the concept, you'll likely still need to make it work well in your own game. I used 60 and 80 and none got stuck while I was testing....
  • Jogos_TDAJogos_TDA PRO Posts: 46
    I think I found the problem: I added a 'display text' with the value of linearvelocity.y and I found out that sometimes linearvelocity value is like 0.00234, so it apears to be zero but it is not...

    I changed the condition from self.motion.linearvelocity.y from 0 to between -2 and 2 and now it works perfectly!

    Thanks for your help bro!
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
  • ericzingelerericzingeler Member Posts: 334
    edited May 2013
    @Jogos_TDA

    Although @jamie_c's fix works, that behavior shouldn't be happening. Based on the video, I think your physics settings are a bit wacky. If you post your project, I can take a look for you.
  • Jogos_TDAJogos_TDA PRO Posts: 46
    @ericzingeler: i did use some abnormal physics atributes: mostly the ball bounciness is set to 1.5 so it accelerates at each bounce... That's why you see the ball 'going crazy' fast.

    After another look at physics settings I found out that when I use friction at about 3 level, it will make the ball slow down after its bounce and cause the ball to get eventually stuck at vertical or horizontal level...

    Here is the code for the basic version with the solution implemented, but it seems not to be working yet. I have added the 'display text' for linearvelocity.y
  • ericzingelerericzingeler Member Posts: 334
    @Jogos_TDA

    Yep, you pretty much said it...

    The bounciness set to 1.5 is the cause of the trajectory interruption and thus eventually ending up stuck like in the video.

    The friction at level 3 is indeed slowing the ball down but not the cause of it getting stuck.

    The simplest solution I think would be to set bounciness of ball and walls to 1 and paddles to let's say 1.25 or more, you should get a nice speed up effect with chances of getting stuck next to impossible.
  • Jogos_TDAJogos_TDA PRO Posts: 46
    Is there a way we can figure out the direction (in 0-360 degree equivelant) and velocity that the ball is going?

    I would like to use 'accelerate ' to increase the ball velocity instead of using 'bounce' to do that.

    But the problem is that when I use 'accelerate' I have to input the direction the ball is going at that time and I dont have that...
  • Jogos_TDAJogos_TDA PRO Posts: 46
    I have found a video by Tshirtboot about how to find the ball velocity (speed).
    Here it is;



    Now the only missing puzze is how to find the angle that th eball is going.

    I'm trying to make up a formula using linearvelocity.x and linearvelocity.y
  • Jogos_TDAJogos_TDA PRO Posts: 46
    @ericzingeler: i did use some abnormal physics atributes: mostly the ball bounciness is set to 1.5 so it accelerates at each bounce... That's why you see the ball 'going crazy' fast.

    After another look at physics settings I found out that when I use friction at about 3 level, it will make the ball slow down after its bounce and cause the ball to get eventually stuck at vertical or horizontal level...

    Here is the code for the basic version with the solution implemented, but it seems not to be working yet. I have added the 'display text' for linearvelocity.y
  • ericzingelerericzingeler Member Posts: 334
    Speed = magnitude(motion.linear.x,motion.linear.y)

    Yes, you can figure out the direction your going using something like:

    vectorToangle(last.position.x - position.x , last.position.y - position.y)

    where last.position.x & last.position.y = position some amount of time ago OR some amount of distance ago

    but... I think your better off with bounce as the above is not trivial.
  • Jogos_TDAJogos_TDA PRO Posts: 46
    Here is the new version displaying 3 info boxes in this order (left to right):
    1) ball speed
    2) ball linearvelocity.x
    3) ball linearvolocity.y

    Still the only missing puzze is how to calculate the ball angle...

    Have fun with the file (attached).
Sign In or Register to comment.