• 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 John Sartain · Aug 23, 2014 at 03:44 AM · mobilecubeballbouncerolling

Everytime ball goes to new plane it bounces

I'm trying to make a game with the rolling ball from sample assets. Everytime ball goes to new plane, cube, etc it bounces. How do I make it not bounce. alt text

first script

using UnityEngine; public class Ball : MonoBehaviour { [SerializeField] private float movePower = 5; // The force added to the ball to move it. [SerializeField] private bool useTorque = true; // Whether or not to use torque to move the ball. [SerializeField] private float maxAngularVelocity = 25; // The maximum velocity the ball can rotate at. [SerializeField] private float jumpPower = 2; // The force added to the ball when it jumps. private const float GroundRayLength = 1f; // The length of the ray to check if the ball is grounded. void Start() { // Set the maximum angular velocity. rigidbody.maxAngularVelocity = maxAngularVelocity; } public void Move (Vector3 moveDirection, bool jump) { // If using torque to rotate the ball... if (useTorque) // ... add torque around the axis defined by the move direction. rigidbody.AddTorque(new Vector3(moveDirection.z, 0, -moveDirection.x) * movePower); else // Otherwise add force in the move direction. rigidbody.AddForce( moveDirection * movePower ); // If on the ground and jump is pressed... if (Physics.Raycast(transform.position, -Vector3.up, GroundRayLength) && jump) { // ... add force in upwards. rigidbody.AddForce(Vector3.up*jumpPower, ForceMode.Impulse); } } } end first script

begin second script

 using UnityEngine;
 
 public class BallUserControl : MonoBehaviour
 {
     private Ball ball;                       // Reference to the ball controller.
      private Vector3 move;                    // the world-relative desired move direction, calculated from the camForward and user input.
     private Transform cam;                    // A reference to the main camera in the scenes transform
     private Vector3 camForward;                // The current forward direction of the camera
     bool jump;                                 // whether the jump button is currently pressed
 
     
     void Awake ()
     {
         // Set up the reference.
         ball = GetComponent<Ball>();
 
         
         // get the transform of the main camera
         if (Camera.main != null)
         {
             cam = Camera.main.transform;
         } else {
             Debug.LogWarning("Warning: no main camera found. Ball needs a Camera tagged \"MainCamera\", for camera-relative controls.");
             // we use world-relative controls in this case, which may not be what the user wants, but hey, we warned them!
         }
 
     }
     
     
     void Update ()
     {
         // Get the axis and jump input.
 
         #if CROSS_PLATFORM_INPUT
         jump = CrossPlatformInput.GetButton("Jump");
         float h = CrossPlatformInput.GetAxis("Horizontal");
         float v = CrossPlatformInput.GetAxis("Vertical");
         #else
         jump = Input.GetButton("Jump");
         float h = Input.GetAxis("Horizontal");
         float v = Input.GetAxis("Vertical");
         #endif
             
         
         // calculate move direction
         if (cam != null)
         {
             // calculate camera relative direction to move:
             camForward = Vector3.Scale (cam.forward, new Vector3(1,0,1)).normalized;
             move = (v * camForward + h * cam.right).normalized;    
         } else {
             // we use world-relative directions in the case of no main camera
             move = (v * Vector3.forward + h * Vector3.right).normalized;
         }
 
 
     }
 
 
     void FixedUpdate ()
     {
         // Call the Move function of the ball controller 
         ball.Move(move, jump);
     }
 }
 

end second script

screen shot 2014-08-22 at 9.59.32 pm.png (66.2 kB)
screen shot 2014-08-22 at 9.59.47 pm.png (47.1 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TwisterK · Aug 23, 2014 at 03:53 AM

Have you ever tried to use physical material? You can create a physical material then set bounciness to 0 then attach it to your collider so that the ball won't bounce.

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

Comment
Add comment · Show 1 · 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 John Sartain · Aug 24, 2014 at 07:25 PM 0
Share

Tried it. it worked ok but the ball needs to be able to bounce. There is a jump button and many heights of stuff. Its just moving from one panel or cube that are right next to eachother somehow it bounces.

avatar image
0

Answer by archie_azares · Aug 23, 2014 at 06:23 AM

change the material attach to the ball. make it metal instead of rubber. rubber has its bouncing properties which make the ball bounce every time it lands on the ground

Comment
Add comment · Show 1 · 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 John Sartain · Aug 24, 2014 at 07:25 PM 0
Share

Tried it with metal it cant climb. it goes a little then falls down

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I get a sphere to bounce of a cube at an angle 1 Answer

intelligent throwing 0 Answers

Cube bounces off wall 2 Answers

How to make a ball that can roll? 2 Answers

How to roll a ball with moving platform. 1 Answer


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