• 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
Question by Ragav R · Jan 08, 2014 at 07:44 AM · ballwall

Ball goes through walls ????

I am new to unity. I am creating a game with ball. I have created a maze with walls(CUBE) surrounded to it. When i move the ball it goes through the walls. I need to fix this. I have used thin box colliders to prevent the ball but still it goes through it. Can anyone tell me the solution for this ? Thanks in advance.

Comment

People who like this

0 Show 5
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 jolo309 · Jan 08, 2014 at 08:22 AM 0
Share

Are you using transform.Translate to move the Ball? Because if you do then it goes through everything since there's no collision detection in transform.Translate

If you want collision you can use rigidbody, look up rigidbody in the Unity scripting reference

avatar image tanoshimi · Jan 08, 2014 at 08:24 AM 0
Share

More information needed: do you have a rigidbody/collider on your ball? How are you moving it? Assuming you have a floor, what did you do to prevent your ball falling through that?

avatar image Ebil · Jan 08, 2014 at 12:38 PM 0
Share

http://docs.unity3d.com/Documentation/Components/class-MeshCollider.html

Are your colliders convex?

avatar image Ragav R · Jan 09, 2014 at 07:08 AM 0
Share

My colliders are not convex. rigidbody/collider are set to ball. I am using rigidbody.AddForce to move the ball. When the ball moves slowly it works good, while the speed of the ball increases it goes through the wall. For the ball these values are set mass is 0.5, speed is 1000, bounciness is 0.8 and Bounciness Combine is maximum.

avatar image Ebil · Jan 09, 2014 at 07:14 AM 1
Share

Well the values you set does not help us, it depends on the code you use. if it is too fast, even continuous collusion detection will not work. You have to make it slower or increase the size of the colliders. You could also program your own "detection". You could check ball distance to wall for example, i dont know if that works for your usecase.

4 Replies

· Add your reply
  • Sort: 
avatar image

Answer by jolo309 · Jan 08, 2014 at 09:20 AM

Are you using transform.Translate to move the Ball? Because if you do then it goes through everything since there's no collision detection in transform.Translate

If you want collision you can use rigidbody, look up rigidbody in the Unity scripting reference

Comment

People who like this

0 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 Ragav R · Jan 08, 2014 at 12:17 PM 0
Share

I am using rigidbody.AddForce(). Here is my code

void FixedUpdate(){ Vector3 dir = Vector3.zero; dir.x = Input.acceleration.x; dir.z = Input.acceleration.y;

if (dir.sqrMagnitude > 1) dir.Normalize();

dir = Time.deltaTime; rigidbody.AddForce (dir fSpeed); }

i have added sphere collider to ball and collision detection as continuous dynamic but still the ball passes through walls. For walls i have added box collider. Please give your suggestion.

avatar image

Answer by emalb · Jan 08, 2014 at 01:07 PM

Maybe the collider on your ball or on the wall is set to Trigger.

Have a look at the Unity Roll-a-Ball tutorial if you haven't already. This provides an example of ball/wall collision in the 'Creating pick-up objects' video.


Edit for additional suggestions...

Try setting the Collision Detection drop down on your ball's Rigidbody to Continuous.

Have a look at the Unity reference material for Rigidbody for more detailed explantion.

I hope that helps!

Comment

People who like this

0 Show 4 · 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 Ragav R · Jan 08, 2014 at 02:08 PM 0
Share

The wall is not set to Trigger. When the ball moves slowly it works good, while the speed of the ball increases it goes through the wall.

avatar image emalb · Jan 08, 2014 at 02:14 PM 0
Share

I've extended my answer with a second suggestion.

avatar image Ragav R · Jan 09, 2014 at 06:29 AM 0
Share

Changed Collision Detection to Continuous but it didn't work. For the ball these values are set mass is 0.5, speed is 1000, bounciness is 0.8 and Bounciness Combine is maximum. This happens, when i move the ball very fast. I don't know why this is happening. Can u please help ?

avatar image Ebil · Jan 09, 2014 at 07:01 AM 0
Share

How about you also answere to the other comments if you want help. It can have many different reasons why this does not work. One I said above, which is obsolete now cause you said it just happens if the ball is moving fast. How fast is it moving? If it is moving to fast its possible your collider is too thin or the ball is simply too fast for your method of collusion detection.

avatar image

Answer by sath · Jan 09, 2014 at 07:18 AM

attach this script to your ball and handle the float values to your needs

Just test it

 public float desiredSpeed = 5000f;
 public float maximumDrag = 1f;
 public float forceConstant = 5000f;
 Rigidbody rigibody;
 

 void Start(){
     rigibody=transform.GetComponent<Rigidbody>();
 }
 
 
 void Update(){
     Vector3 dir = Vector3.zero; 
     dir.x = Input.acceleration.x; 
     dir.z = Input.acceleration.y;
     Vector3 forceDirection = new Vector3(dir.x, 0, dir.z);
     //This reduces drag when the player adds input, and makes it stop faster.
     rigidbody.drag = Mathf.Lerp(maximumDrag, 0, forceDirection.magnitude);
     // this reduces the amount of force that acts on the object if it is already
     // moving at speed.
     float forceMultiplier = Mathf.Clamp01((desiredSpeed - rigidbody.velocity.magnitude) / desiredSpeed);
     // now we actually perform the push
     rigibody.AddForce(forceDirection * (forceMultiplier * Time.deltaTime * forceConstant));
 
 }
Comment

People who like this

0 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 Ragav R · Jan 09, 2014 at 12:33 PM 0
Share

Thanku for your help. i have tried this code but still the ball goes out when i move fast. i have tested with some float values like 1000, 2000, 500, 4000 etc. but goes out.

avatar image

Answer by swatatunity · Jul 26, 2017 at 07:50 PM

I was seeing the same issue and I was able to resolve it by setting "Size" parameters under "box collider" to 1,1,1 instead of 0,0,0 (default).

Comment
Zyriab

People who like this

1 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 Zyriab · Sep 07, 2017 at 04:24 PM 0
Share

That worked for me, the default BoxCollider for a Unity 3D Cube object was (x:1,y:1,z:0). I changed the 'z' parameter to 1 and it works. Thanks mate !

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

24 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to make a player die on collision 2 Answers

Stop ball rolling off wall but bouncing off 1 Answer

collision with wall so player dies 1 Answer

Wall jumping problem 1 Answer

Wall Issue 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