• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Forrest · Apr 28, 2011 at 11:37 PM · aicontrollerpongpaddle

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Meater6 · Apr 29, 2011 at 12:02 AM 0
Share

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.

avatar image Joshua · Apr 29, 2011 at 12:29 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Clunk · Oct 10, 2011 at 03:31 AM

Here's the very simplest way you can try out. T$$anonymous$$s will be good for practicing pong on your own lol. Attach t$$anonymous$$s 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 t$$anonymous$$s script. Or, just tag the ball with say, "ball". Then put t$$anonymous$$s 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;

 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Enemy controller.move script slows down and speeds up. How to get it consistent? 0 Answers

Animay play in editor 0 Answers

AI Script attached to Enemy and is Rotating around player 0 Answers

Fast Script Ai For mobile: Navmesh or A*? 1 Answer

C# Script Not Working? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges