Page 1 of 1

motion actor on *Y* for other actor

PostPosted: Mon Feb 09, 2009 11:54 am
by Romol
motion actor on *Y* for other actor :)

I do the ping-pong . such problem! how I do that enemy (the stick) moved for ball only from up and down , not moving to the right and to the left? :cry: :cry: :cry:

Re: motion actor on *Y* for other actor

PostPosted: Mon Feb 09, 2009 2:46 pm
by Kalladdolf
From what I got, you are trying to make the enemy actor move along the y axis according the y position of the ball actor?
That can be done this way: Put the following script on the DrawActor Event of the opponent stick actor:
Code: Select all
if(y < ball.y - 20 && yvelocity < 7) // if the enemy player's y is above the ball's y value
{yvelocity += 1;} // accelerate by one
if(y > ball.y + 20 && yvelocity > -7) // the same goes the other way round.
{yvelocity -= 1;}

7 and 1 in this code are specific speed values I used in this case to make the opponent look human, you may change them as you like.
20 is a distance the actor has to keep from the ball before moving, otherwise it would look pretty odd and wobbly, and the enemy almost wouldn't be able to lose. If you make the value bigger, the level will be easier, if you reduce it though, the enemy will give you a rough time.
And welcome to the GE forums. :)


*Apologizes to fuzzy for using if(), I just thought this would be the easiest solution without confusing people.*

Re: motion actor on *Y* for other actor

PostPosted: Mon Feb 09, 2009 8:03 pm
by Romol
Thank you! has rescued! Thank you! I now lucky person :lol: :lol: :lol: ! itself I in general write can not languages , :cry:

Re: motion actor on *Y* for other actor

PostPosted: Tue Feb 10, 2009 3:24 am
by Fuzzy
Kalladdolf wrote:*Apologizes to fuzzy for using if(), I just thought this would be the easiest solution without confusing people.*


That is the perfect time to use if()! Well done! Good job on the comments too.