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
0
Question by Djaydino · Sep 01, 2012 at 11:17 PM · androidrotateballpongroll

pong rolling ball

hi , i'm still young at unity and java and my first project is a pong like game (2d)

i got everything working except my ball is not rolling.

it is moving but when i added my ball texture i noticed it is not "rolling"

i use this to start moving my ball :

 gameObject.rigidbody.AddForce(200,randomAngle,0);

Then to speed up the ball i use :

 function OnCollisionEnter(theCollision : Collision)
     {
 
         if(theCollision.gameObject.name == "Player1")
         {
         gameObject.rigidbody.AddForce(rigidbody.velocity.normalized * 55);
         audio.PlayOneShot(paddleSound1);
         }
         if(theCollision.gameObject.name == "Player2")
         {
         gameObject.rigidbody.AddForce(rigidbody.velocity.normalized * 55);
         audio.PlayOneShot(paddleSound2);
         }

there is no gravity and its 2d.

i think i have to get the x and y direction + the velocity to give it to the rotation but i don't know where to start atm, and maybe there is an easier way to do that.

thanks in advance for helping :)

Comment
Add comment · Show 1
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 Djaydino · Sep 02, 2012 at 06:54 PM 0
Share

ow and it is front view btw :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by nikescar · Sep 02, 2012 at 10:31 AM

The easiest way to do this would be to actually have the ball roll on a surface with a certain friction. Add a plane and enable gravity. If you want to calculate the correct rolling rotation without using the built-in physics that would do this for you, then you are in for a lot of fun/frustration.

I guess my follow-up question would be why do you want to do it without the physics engine?

Comment
Add comment · Show 2 · 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
avatar image Djaydino · Sep 02, 2012 at 11:58 AM 0
Share

my whole game is on side view atm and so i would have to turn everything to top view .

the reason is i that i want to make a kind of random rotating effect on it, for example to give it extra top spin, side spin or other effects.

i found how to get the velocity , x and y :

 var testDisplayVel : GUIText;
 var testDisplayX : GUIText;
 var testDisplayY : GUIText;
 
 
 function Update () {
 var ballSpeed = rigidbody.velocity.magnitude;
 var xDirection = rigidbody.velocity.x;
 var yDirection = rigidbody.velocity.y;
 testDisplayVel.text = ballSpeed + "speed";
 testDisplayX.text = xDirection + "x";
 testDisplayY.text = yDirection + "y";
 
 
 }

i think i will manage to get my ball rolling now, thx for the help anyway. if i got it rolling good i put my script here if someone else needs it :)

avatar image Djaydino · Sep 02, 2012 at 09:14 PM 0
Share

my ball is rolling now But not @ right direction i did this :

function Update () { var ballSpeed = rigidbody.velocity.magnitude; var xDirection = rigidbody.velocity.x; var yDirection = rigidbody.velocity.y;

transform.Rotate(yDirection ,-xDirection , 0); }

when i only use :

     transform.Rotate(0 ,-xDirection , 0);

it rolls good in the x direction, and when i use :

     transform.Rotate(0 ,-xDirection , 0);

it rolls good in the y direction, But when i use both it starts good but after collition it goed into strange directions

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to roll a ball ? 2 Answers

Making a ball roll and keeping the axis? 2 Answers

Add tilt function to rotate a ball android device 0 Answers

Rolling a ball in 2D, in direction of movement 1 Answer

Stopping rotation at 90° and -90°/270°. 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