playMaker

Author Topic: Writing an FSM that uses Rigidbody.AddForce to move a specific position[SOLVED]  (Read 3708 times)

90degreedesigns

  • Playmaker Newbie
  • *
  • Posts: 13
I am developing a free (and ad-free!) Pong-themed game and need a paddle to follow the ball. Ideally, the paddle will have a variable to allow for the paddle to "dumb-down," and give the ability to hit the ball past the paddle over time.
Of course I can't set position on the paddle, since that messes with the physics and eventually the paddle will "consume" the ball, causing game play to stop.

My question is this, what type of State would I need to use 'Add Force' in order to have the paddle follow the ball?

I've already tried two ways:

1: Use set position anyway. Either the paddle will pass through the ball and the ball will be stuck in half, or the paddle will add so much velocity to the ball it will throw the ball through the walls of the game area and off into space.
2: Ball's Y position = BallY
     Paddle's Y position = PaddleY
     BallY-PaddleY = padforce
     Apply padforce to paddle.
     When PaddleY=BallY,  Use addforce(vector.zero)
When I do this, the paddle looks drunk.

Any suggestions?

Attached is an image of my Pong game to show that in all actuality, I only need to follow the ball on the Y axis. The computer player (on right) will remain locked in its X and Z axis. Also, when I get this finished in a few days, I'd like to post a link in case anyone would like to play :)

« Last Edit: January 10, 2014, 06:17:13 AM by jeanfabre »

90degreedesigns

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Writing an FSM that uses Rigidbody.AddForce to move a specific position
« Reply #1 on: January 09, 2014, 08:40:27 AM »
I may have spoke too soon..

I didn't realize there was a Move To action until just an hour ago!
So my states look like this:

1: Check the distance from the right paddle to the ball. If the distance is >7 then go to state 2

2: Move to ball, then send to state 1.