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 mCaNDReu · Dec 16, 2012 at 03:47 AM · physicsballroll

How to make a ball roll by pushing it with a cube?

Hello,

Here is the scenario. I made a plane with a ball on top and a cube. The cube I made controllable with the mouse x and y positions, and is a rigidbody as well as the ball. I wanted to be able to push the ball around with the cube which did work but what I'd like to happen is that the ball would keep rolling after I hit it with the cube and it doesn't do that. The ball is just pushed around by the cube but stops when the cube stops pushing. Help.

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 Cool Dave · Dec 16, 2012 at 04:31 AM 0
Share

There are lots of possible causes.

$$anonymous$$ight be pushing it too slow.

The ball might not actually be rolling, just sliding.

$$anonymous$$ight be too much friction.

Hope this helps.

1 Reply

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

Answer by clunk47 · Dec 16, 2012 at 05:02 AM

You would want to add constant force to the sphere in the direction of the cube's velocity. So you want to be moving the cube with physics (force) when using the mouse axes. I wouldn't use transform.Translate or anything like that. Just test out this simple script I've wrote for your question to see if it get you what you want. Disable any code you're using now if any. Attach this C# script to the CUBE. Be sure to name the C# script EXAMPLE because that's what I have the class name as, which you could always change. I've also turned up the max angular velocity of all rigidbodies via this script, so the ball can actually "roll" and not slide.

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(Rigidbody))]
 
 public class EXAMPLE : MonoBehaviour
 {
     float ZSpeed = 1.0f;
     float XSpeed = 1.0f;
     
     void Start()
     {
         rigidbody.freezeRotation = true;
         rigidbody.drag = 5.0f;
             Physics.maxAngularVelocity = 100.0f;
     }
     
     void Update()
     {
         rigidbody.AddForce(new Vector3(Input.GetAxis ("Mouse X") * XSpeed,
             0, Input.GetAxis ("Mouse Y") * ZSpeed), ForceMode.Impulse);
     }
     
     void OnCollisionEnter(Collision other)
     {
         if(other.rigidbody)
         {
             if(!other.gameObject.GetComponent<ConstantForce>())
                 other.gameObject.AddComponent<ConstantForce>();
             else
                 other.rigidbody.constantForce.force = rigidbody.velocity;
         }
     }
     
 }
     


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

11 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

Related Questions

How do I move my object through physics with my keyboard? 1 Answer

How to make a ball that can roll? 2 Answers

Get a free moving ball. 1 Answer

Making a ball roll and keeping the axis? 2 Answers

Create a "free" rolling ball controlled by player 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