Brick Block: How to make paddle influence the movement of ball

bobby6478

  • Posts: 89
Hello, I have just posted a version of brick block on kongregate, and I have noticed that the same bricks are broken in the same order every game. I was wondering, does anyone know how i could make the speed and direction of the paddle when it comes in contact with the ball affect the speed and direction the ball goes in e.g. the paddle is going at a speed of 24 to the right and the ball is coming down at a 45 degree angle also going speed 24, the ball goes in the same direction and at the same speed that it would go even if the paddle isn't moving, which isn't good. If someone finds a way to do this, please help me. Thanks
"I don't know what my calling is, but I want to be here for a bigger reason. I strive to be like the greatest people who have ever lived." -Will Smith

Hectate

  • *
  • Posts: 4643
You'll need to find the code that controls the ball bouncing off of the paddle - assuming you're not just handling it with physics. In either case, you need to have an event that modifies the ball's movement when it collides with the paddle. In most brick breaking games, the ball moves to the left if it hits the left side of the paddle, and vice versa. If you'd rather modify it based on the movement of the paddle, you could get the X speed of the paddle and use it to determine an amount of x force to apply to the ball instead.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

bobby6478

  • Posts: 89
I attempted to do what you said for about an hour and miserably. If possible, could you replicate this and post a screen shot. I know you may not want to do that but if you are willing, it would be very helpful to follow a screen shot of how to do this. I would be very thankful.
"I don't know what my calling is, but I want to be here for a bigger reason. I strive to be like the greatest people who have ever lived." -Will Smith

Hectate

  • *
  • Posts: 4643
No I can't, sorry. Perhaps you could detail what you've tried so far?
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

bobby6478

  • Posts: 89
Basically the second one, "you could get the X speed of the paddle and use it to determine an amount of x force to apply to the ball" I tried it, and couldn't find a way to determine a force or direction to the ball. I attempted the first of your suggestion too, however, I have noticed that stencyl consideres the left side of an object on the actual side. For a visual

                                    _____________________________
                                   |                                                    |
  Left side of object ->   |                                                    |
                                    |____________________________|

as you can see, the ball will not hit this part of the object, so please tell me, how would I make it so that the left half of the paddle influences direction, instead of just the left side. If this is impossible, could you tell me how I would go about making your second idea a reality. I know that you do not hold all the answers, but just point me in the right direction and I MAY be able to find my way. Thanks again. :)
"I don't know what my calling is, but I want to be here for a bigger reason. I strive to be like the greatest people who have ever lived." -Will Smith

coleislazy

  • *
  • Posts: 2607
You could try placing additional collision shapes on your paddle actor, make them sensors and give them distinct collision groups. Then, when they collide, you can check the collision group and know which part of the paddle was hit. Once you know that, you can apply an additional force to the ball via the "push actor toward" blocks.

Hectate

  • *
  • Posts: 4643
For the "left half" you want to see if it hits on left-of-center of the paddle, not the left edge. You would need to compare the X locations of the actors to do so. The collision shape idea is good as well.

To compare X locations:

When the ball collides with the paddle:
If ( X-Center of Ball < X-Center of Paddle )
  { apply force to move the ball left }
Otherwise If ( X-Center of Ball > X-Center of Paddle )
  { apply force to move the ball right }

So if the X-Center of the paddle is at 50 and the X-Center of the ball is at 45 when it hits the paddle - the ball is on the left half of the paddle and should be pushed leftward (or at least have some amount of force applied in that direction). But if the X-Center of the paddle is 50 but the X-Center of the ball is 60 instead - it's hit the paddle on the right half instead.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

bobby6478

  • Posts: 89
We were so close-

I did what I was told, and it worked, but now an EXTREME lag has set in, making the game virtually unplayable. The lag makes me play the game 1 frame per second. What can I do?
"I don't know what my calling is, but I want to be here for a bigger reason. I strive to be like the greatest people who have ever lived." -Will Smith

Hectate

  • *
  • Posts: 4643
First, check the ingame console (press the ~ button to find it on most keyboards) to see if there are any errors. Tell us if it says anything.

Second, show us the behavior you've created to do this. Whichever one you just changed that introduced the lag.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

bobby6478

  • Posts: 89
I could not open the ingame console. Here is a screenshot of the behavior I created . Note that max speed is 20 which is why the force is 20 and I had to choose last collided actor because it was the only other option...
"I don't know what my calling is, but I want to be here for a bigger reason. I strive to be like the greatest people who have ever lived." -Will Smith

Hectate

  • *
  • Posts: 4643
It should not be in Always. It should be a collision event.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

bobby6478

  • Posts: 89
I do not know if anyone else has wanted to do this before, but if they have, below I have attached an image containing the SCENE behavior which is needed to program the game to do this. Note that it did work for me.
"I don't know what my calling is, but I want to be here for a bigger reason. I strive to be like the greatest people who have ever lived." -Will Smith

snortch

  • Posts: 25
Just because I am trying to learn, I decided to try to apply Cole's suggestion. Here is Cole's suggestion again:

You could try placing additional collision shapes on your paddle actor, make them sensors and give them distinct collision groups. Then, when they collide, you can check the collision group and know which part of the paddle was hit. Once you know that, you can apply an additional force to the ball via the "push actor toward" blocks.

Here is what I did - and where I am running into problems:

1. I drew a rectangle and placed it on the left and right side of the paddle shape. I created a unique collision group for the left collision rectangle and the right collision rectangle. I also created a center collision shape. I set the left and right collision shapes to sensors, but unchecked the "sensors" option for the center shape.

2. For these three collisions shapes, I setup the collision group to collide with only the breakout ball.
3. For the Ball, I created the following event just for the left paddle sensor to start with:


I can't get this to work. If the ball lands on either the left side of the paddle where I setup one of the collisions sensors, nothing happens to it. I'm hoping that hitting the left side will cause the ball's trajectory to change so that it doesn't just bounce straight up and down. Once I can get it to work on the left side, I will apply the same thing to the right side.

Any ideas why my setup isn't working?

TIA for any suggestions.


« Last Edit: August 27, 2012, 03:51:23 pm by snortch »

coleislazy

  • *
  • Posts: 2607
Have you tried a stronger force, or changing "gently" to "sharply"? A "gentle" force of 20 is pretty low.

snortch

  • Posts: 25
Yea, I tried that. I also tried limiting the number of collision shapes just to rule out any possibility of interference. Here is what happens:

http://screencast.com/t/hoJryvACfVa