Hi! I have made a Pong game which is single-player for Android. I have just one issue :
My game has a Player Paddle object which is what the Player controls. The Enemy follows the ball. The speed of the Enemy is controllable. There are different levels wherein, every level up you go, the speed of the Enemy decreases. Now if I make the speed of the Enemy too fast, it never loses. And, it never wins if it’s speed is too low. How can I make the win/loss streak random, wherein the Player wins once in a while, and so does the Enemy.
An answer was posted in another place but I don’t have the skills to code it out as I am a beginner to Unity and would love it if someone could help me with the coding etc. that is required to execute it. It is written down :
“make it so that after the enemy paddle has hit the ball it automatically returns to the (vertical) middle of the screen. only once the ball returns to the (horizontal) middle of the screen does the enemy begin following the ball again.”
Hope someone can help me with this. Cheers!
I’d suggest generating a random number on each move and multiplying the enemy paddle speed by that. ie. multiplying it’s speed by 0.70 is going to slow it down and give it a 30% handicap for that movement but on the next move the random number might be 0.99 which will result in it going almost full speed.
float randomNumber = Random.value;
paddleSpeed = paddleSpeed * randomNumber;
You just need to work out the range of the handicap you want and make it less and less as the game gets harder. You could also think about a reaction time variable which would create a delay before it moves towards the ball and again randomise that. Put the two together and you should get something that looks more human and less automatic.
Hi! Thanks, @Fredex8 and @Owen Reynolds, for your answers. I have implemented the idea of the Random.value thing. I got it working and it looks quite human now. I set the speed of the Enemy at a Random Range (9 and 3 - can be controlled) which changes when the Ball touches the Enemy Paddle.
My previous problem is solved in which, either the User or Enemy lost. Thanks for that.
I have one issue though - The speed 3 is a little too low for the enemy which could be generated by the computer randomly. Now, it remains too slow for the Enemy to hit the ball again after he already lost the previous point. Therefore, I had an idea of putting an invisible Trigger at the end of the screen which resets the speed of the Enemy to possibly a greater number through which the Enemy can at least return the next ball. I tried several times but I couldn’t figure out how to use the function ‘OnTriggerEnter’ properly. It would be great if someone could help me with the code or give me a reference to a video which describes this solely. Sorry for being so helpless. Thanks.