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 Styxer · Dec 09, 2013 at 03:38 PM · rigidbodyscriptingbasics

problem with ball mechanics

Hey guys im trying to make a "block breaker" game and i want to my ball to bounce like in the game and i managed to do this script

 void Start () 
     {
         rigidbody.AddForce (150f, 450f, 0);
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 

but in the best case its only bounce back to where the ball was dropped from and it aint going sideways as it should do thanks

Comment
Add comment · Show 3
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 Styxer · Dec 09, 2013 at 07:16 PM 0
Share

it seems as the ball hit the paddle its loses momentum also i changed the bounce threshold to 0 on project setting and bounce combine to max on phyball(which is the material for the ball)

avatar image Styxer · Dec 09, 2013 at 07:16 PM 0
Share

now its going sideways as it should do but up and down only the where the ball was dropped at the best(also it seems the ball loses momentum if its going sideways)

avatar image Styxer · Dec 10, 2013 at 03:03 PM 0
Share

such a simple solution thanks man :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by guitarxe · Dec 09, 2013 at 04:32 PM

Unity's physics mimics real life. There is nothing in real life that would make a ball that is dropped from a height onto a uniform surface to bounce to the left or right. It will bounce straight back up.

In order to make the ball bounce to the left or right the way you want to, you will have to write additional code to handle that behaviour. Start first by simply making it bounce in one particular direction all the time. Once you get that working, you can think about getting it to bounce in different directions depending on where the ball lands on the paddle.

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 Styxer · Dec 09, 2013 at 06:41 PM 0
Share

oky i rewrote both my paddle and my ball scripts and now it go sideways as it should do but not up(till the edge of the screen as it should do) ball script: **using UnityEngine; using System.Collections;

 public class BallScript : $$anonymous$$onoBehaviour {
 
     // Use this for initialization
     void Start () 
     {
         rigidbody.AddForce (0, 450f, 0);
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }**

paddle script:

 **using UnityEngine;
 using System.Collections;
 
 public class PadleScript : $$anonymous$$onoBehaviour {
 
     public float peddlespeed=10f;
 
     // Use this for initialization
     void Start () {
 
     
     }
     
     // Update is called once per frame
     void Update ()
     {    
         transform.Translate (peddlespeed * Time.deltaTime * Input.GetAxis ("Horizontal"), 0, 0);
     }
     void OnCollisionEnter (Collision col)
     {
         foreach (ContactPoint Contact in col.contacts) 
         {
             if ( Contact.thisCollider==collider)
             {
                 float english = Contact.point.x - transform.position.x;
                 Contact.otherCollider.rigidbody.AddForce(300f*english,0,0);
             }
         }
     }
 
 }**
 
avatar image guitarxe · Dec 09, 2013 at 08:20 PM 0
Share

Not all the way up to the top edge of the screen? You're adding a certain amount of force on the ball, but you know that there is gravity also acting on the ball which makes it fall back down, right? You can change this gravity settings from project settings > physics, or on the RigidBody component of your ball, just uncheck the Use Gravity box.

Since you are trying to recreate a "breakout" game, once a ball is launched there should be no other forces acting on it, such as friction, otherwise the ball will eventually lose its velocity and come to a stop - not what you want in a "breakout" game.

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

18 People are following this question.

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

Related Questions

Why is my object tilting when moving? 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Rigidbody AI script needed 0 Answers

add force get stronger over time slow. 2 Answers

Flight sim script help 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