- Home /
Pong AI/Paddle controller help
Hi i'm pretty new to unity and i thought a good place to start when making games would be making Pong or so i thought there is a tutorial that helped a lot and the Ball physics script works but for some reason the Paddle controller script doesn't work. Heres the tutorial-http://www.youtube.com/watch?v=GE4scGszipY&feature=related and also if someone could help me with the paddle ai that would be great thanks
For the paddle AI, make the paddle move at a constant speed to the ball's z position (if that is the right axis), so if it moves fast enough it can hit the ball. Or you can make it only move when the ball is on AI side by either triggers or just using the balls position. Also, it would be helpful if you put more information in the question. Hope this helps.
Hah, thats how I got started as well. Epicness. Indeed, contantly move the enemies paddle to the balls z position by a constant speed is the way it's done.
Answer by Clunk · Oct 10, 2011 at 03:31 AM
Here's the very simplest way you can try out. This will be good for practicing pong on your own lol. Attach this to the enemy paddle. Make the paddle a rigidbody and use rigidbody constraints to allow the paddle to move only on one axis, and lock rotation. Make the ball a rigidbody, and give it the physics material "Bouncy". Simple script, but it will get you started. I set the paddle's Z velocity to 9/10ths of the ball's z velocity, so you can beat the AI, but not too easily. You need to drag the ball object into the inspector after you attach this script. Or, just tag the ball with say, "ball". Then put this in the Start() function. {ball = GameObject.FindObjectsWithTag("ball");} That of course is after making a variable, var ball;
var ball : Transform;
function Update()
{
rigidbody.velocity.z = ball.rigidbody.velocity.z * .9;
}
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "ball")
{
collision.rigidbody.velocity.x= -20;
}
}