Need help with Brick Breaker game

I making this brick breaker game, but sometimes the ball moves either straight up and down or horizontally. This causes the player to be messed up. How do I make a rule that when this happens the ball changes directions?

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    You need to check the balls linear velocity.X and linear velocity.Y if either are ever exactly equal to zero, you need to change it to another value. So you would set up a rule like this for the side to side check:

    Rule:
    if Self.Motion.Linear Velocity.X = 0
    Change Attribute Self.Motion.Linear Velocity.X to [something else not 0]

    For the [something else not 0] you could use the random function to pick a random number so it does not always do the same thing.

    Hope that helps.
  • rajit.garg11rajit.garg11 Member Posts: 11
    I am making this brick breaker a game where I change scenes to another when it runs out of lives. My code is: if game.lives = 0, change scenes to game over. Somehow this doesn't move to the game over scene and it also freezes the game. Can you please help?
  • rajit.garg11rajit.garg11 Member Posts: 11
    This doesn't work for some reason.
  • Thunder_ChildThunder_Child Member Posts: 2,343
    Are you also including a counter so that they count down to zero?
  • rajit.garg11rajit.garg11 Member Posts: 11
    I put in a piece of code where if the ball collides with the bottom game.lives - 1.
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    You'll have to post an image of your rules for anyone to have any idea why it doesn't work for you.
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    I'd check to make sure that the lives attribute actually has a value of 0. Sometimes, because of how the code is set up, the attributes can get out of whack and subtract more than one or even skip over a Change Attribute behavior. Use a Display Text behavior and check to make sure that the attribute is set to 0 when you want the scene to change.

    Simple debugging, but usually helps find the problem quickly.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    [Merged threads]

    Please don't create multiple threads for the same question.
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    I've attached a sample file that un-sticks a ball if/when it's stuck on the X or Y axis. It will start stuck on the X axis, when you press the space bar it will un-stick. Anytime it gets stuck again, press the space bar to fix it.

    To make this work in a pong game you'd want to use the rules I have set up that are triggered by the space bar, to be triggered when the ball hits a wall or a paddle.

    Hope this helps.
Sign In or Register to comment.