Make paddle follow ball but slower?

Hello, guys!

I'm really having trouble making my paddle follow the ball slowly. The paddle follows the ball with no problem... but since it's constrained to it's position, it always catches the ball. I want the paddle to move slower than the ball so I can just adjust it with a difficulty level. I tried interpolate but it only works on the first serve... after that it doesn't follow the ball anymore. =(

Please help.

Comments

  • carlblanchetcarlblanchet Member Posts: 755
    edited October 2012
    Dont fully understand so ill throw this out there anyway:

    have you tried constraining with an offset?

    Constrain Attribute/ self.position.x to BallX-50 (or any other numbers)
  • sSHAKESssSHAKESs Member Posts: 27
    Hello!

    Well, I have constrained the paddle to the ball's movement. So, it follows it exactly. But then, that would mean the cpu would be unbeatable. So, I want to adjust the paddle's speed when it's following the ball. I want it to be slower.

    I tried offsetting it but it looks unnatural. And if I offset it like so, then it would always not catch the ball. I tried adding interpolation but it only works on the first serve. It doesn't work anymore once it returns the ball... the paddle just stops.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited October 2012
    Start with something like this:

    When game.ballY < self.Position.Y-10
    --Change Attribute: self.Motion.Linear Velocity.Y To: -100
    Otherwise
    --Change Attribute: self.Motion.Linear Velocity.Y To: 0

    When game.ballY > self.Position.Y+10
    --Change Attribute: self.Motion.Linear Velocity.Y To: 100
    Otherwise
    --Change Attribute: self.Motion.Linear Velocity.Y To: 0


    Also, If you get rid of the two 'otherwise' behaviors, the paddle will do a kind of anticipatory dance that might add some character to it.
  • sSHAKESssSHAKESs Member Posts: 27
    edited November 2012
    @RThurman Hello! I'm sorry... I tried as you said but the paddle is not moving... I must be doing something really wrong... :(

    - So my game is in portrait mode so I changed all to the X axis.
    - I then constrained the game.ballX attribute to the ball.
    - And did as you listed in the paddle.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    hmmm.... there are a number of things that might be going wrong. Without knowing your famaliarity with GameSalad I am not sure of where to start. Here are a couple of guesses:

    1) You can't copy and paste the attributes. You need to get them from the drop-down menus.
    2) You will need to replace "game.ballY" with the attribute you are using to save the position of the ball. ("game.ballY" was only meant to give you an idea that you need to have a game-level attribute that records the ball's Y position.)
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Use a move to behavior and randomize the speed it goes to the position. Then after it makes contact with the ball make the paddle return to a default position
  • sSHAKESssSHAKESs Member Posts: 27
    @RThurman

    Sigh... this is sorta frustrating. I'm sorry for being such a newbie.

    1. Yep. I know I can't copy and paste.
    3. Yes. I did constrain the 'game.ballY' to the ball's position. I am using a different attribute name.


    @FryingBaconStudios

    I can never get the 'move to' behavior to work. So can I just put 'game.ballY' in the X Position of the 'move to' behavior? That's what I did and it doesn't move. :(
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited November 2012
    GameSalad is like learning to ride a bike; 1) nothing works until it all works, 2) all that's needed is a little push down a gentle hill.

    Push:
    http://www.mediafire.com/download.php?0tq004ybz4yaulg
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    I'm working on a game that uses paddles and one is a computer player and yes it is tricky to get it to perform. I used a move to behavior to contact the puck when it crosses a point on the screen and the I used interpolate to move it to the default position after contact.
  • sSHAKESssSHAKESs Member Posts: 27
    @RThurman

    Okay, don't kill me... but I found out why it wasn't working before... the paddle wasn't MOVABLE! Grrrrr!!! So... what you gave me works now!!! :D I'm so happy! Thanks so much!!!

    Only problem now is that when the ball goes in the goal, or the ball's not in the court, the paddle is moving from left to right because it's waiting for the ball.

    Like what @FryingBaconStudios said, how do I make it move back to a default position when the ball is in the goal or when it's waiting for the next round?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Glad its working for you!

    The next issue seems like a completely different topic. It sounds like its time to make a new thread and ask how to move a paddle back to its starting position once the ball is out of play.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited November 2012
    Make a Boolean that is true when the ball is in the goal and in your rule that returns it to the default position change it to any and add the ball in goal attribute to the rule conditions. Be sure to add change attribute to false in the otherwise section of the rule that turns it to true when it's in the goal.
Sign In or Register to comment.