Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Sebadam · Dec 18, 2014 at 01:28 AM · 2 player

How to add spin to a ball in Pong game

So I'm creating a 2D pong game, and I'd like to implement a spin to the ball whenever the player, for example moves down, creating back spin. Or if the player moves up, creating top spin.

And if the ball had some top spin to it, and it hit the other player( who wasn't moving ) then I'd like for it to move in the up direction, opposite with backspin.

Another thing I'd like to implement would be, if the ball had topspin creating, I'd like for it to keep on getting more and more spin if both the players allow it to spin the same direction.

I haven't got much code on this as I have no idea how I would implement this, I've tried messing around with rigidbody2D.rotation but it doesn't seem to affect much as I'm not completely sure on how to use this.

A game that does this type of physics well, is Sports Heads: Football (This is for reference if someone isn't sure what I mean)

This is the only bit of code I have concerning the player and ball's interaction.

 function OnCollisionEnter2D (colInfo : Collision2D) {
 
     if(colInfo.collider.tag == "Player") {
         //The velocity of the ball is, the player's velocity/2 + the ball's velocity/3;
         rigidbody2D.velocity.y = rigidbody2D.velocity.y/2 + colInfo.collider.rigidbody2D.velocity.y/3;
         
         audio.pitch = Random.Range(0.8f, 1.2f);
         audio.Play();
 
         
     
     }
 
 }

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 Sebadam · Dec 18, 2014 at 01:56 AM 0
Share

@$$anonymous$$rSoad I'm very new, I'm not sure how to make that work, what I've tried doing is this:

 rigidbody2D.AddTorque (rigidbody2D.velocity.y * 10); 

to the OnCollisionEnter2D function shown in my post, but I don't really see a noticeable difference.

avatar image Sebadam · Dec 18, 2014 at 02:23 AM 0
Share

@$$anonymous$$rSoad Ah thankyou :) I will mess around with that and see what happens, I'll ask you more questions if/when needed.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by MrSoad · Dec 18, 2014 at 02:21 AM

Take a look at this :

http://docs.unity3d.com/ScriptReference/Rigidbody2D.AddTorque.html

How much effect you get will depend upon several things inc how much friction you get between your ball and your bats.

1)Try out different physical materials on your ball and bats :

http://docs.unity3d.com/Manual/class-PhysicMaterial.html

2) Goto : Edit -> Project Settings -> Physics . Now look at "Max Angular Velocity" which will prob say 7. Up this a lot to 40 or 50 ish, this is the max spin any object can have and 7 will not be enough for what you need.

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Using Input.GetAxis on a 2 Player Game 2 Answers

Computer game for 2 players with AUTODETECTION for the gamepads 0 Answers

Help for basic board game but for me it's hard.. 0 Answers

Need help with camera for 2 player roll a ball. 1 Answer

how to make two player bounce off each other but not with the ground? 0 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