Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Siegeon · May 21, 2011 at 05:15 PM · collision detectionrigidbody collision

Prevent a fast moving ball from passing through a wall

I need help with preventing a fast moving ball from passing through a wall. For a testing environment I have a basic sphere with a sphere collider radius .5, and a rigid body that is set to continuous collision detection. The wall is 1 unit thick with a box collider, and the paddle is .8 units thick and also has a box collider. The distance from the paddle to the wall is 57. Every time the ball hits the paddle its velocity is increased by 1. With out fail every time the velocity of the ball reaches 54 it will pass through the wall. I have tried all the built in collision detection methods, but regardless of which is selected it will pass through the wall at velocity total of 54. Here is an example of code used to increase the velocity of the ball, this code is attached to the paddle; I have cut out all the math for dealing with the angles of the bounce, and would like to just focus on the speed issue.

 using System;
 using UnityEngine;
 using System.Collections;
 public class PaddleScript : MonoBehaviour
 {
 public float ballSpeed = -20f;
 public float velX = 0;
 public float velY = -20f;

    void OnCollisionEnter(Collision collision)
    {

       if(velY>0)
       {
          velY = ballSpeed - Math.Abs(velX);
       }
       else
       {
          velY = (ballSpeed - Math.Abs(velyX));
       }
       collision.rigidbody.velocity = new vector3(velX,velY,0);
       ballSpeed += 1;
     }
 }
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
3
Best Answer

Answer by demize2010 · May 21, 2011 at 07:09 PM

Hi mate,

CCD will not help you if your object is moving very fast. We had a simillar problem with an object that was moved by a player drag action.

The issue is basically that your object moves past the collision point between frames, so even CCD will no save you, but it will munch cycles like no tomorrow.

This script helped us no ends:

http://www.unifycommunity.com/wiki/index.php?title=DontGoThroughThings

Comment
Add comment · Show 10 · 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 Siegeon · May 21, 2011 at 07:29 PM 0
Share

That is a great script, it did allow me to speed the ball up to 68 with the skin width set to 1. However I need to get the ball up to a speed of about 90 before capping it out, any other ideas?

avatar image Peter G · May 21, 2011 at 08:38 PM 0
Share

The issue is basically that your object moves past the collision point between frames, so even CCD will >no save you, but it will munch cycles like no tomorrow.

This statement isn't true. The whole point of CCD is to stop objects from doing that.

avatar image Siegeon · May 21, 2011 at 08:50 PM 0
Share

I understand that is the purpose of CCD is to prevent the object from moving though other objects, however it does not do its job past as specific speed; in my case that speed is 54 without the DontGoThroughThings script attached.

avatar image demize2010 · May 21, 2011 at 10:08 PM 0
Share

Yup CCD improves things but it is still dependent on your frames. You could try CCD and the script at the same time but I'm not 100% confident... have you tried alternate methods of producing the illusion of speed?

avatar image Siegeon · May 22, 2011 at 01:55 PM 0
Share

No demize2010 I have not, nor am I sure what you mean.

Show more comments
avatar image
2

Answer by duyanh2812 · Mar 18, 2014 at 06:51 AM

it's also my trouble and i found simple solution when i increase scale object, because your object so small than wall or other object then it's passing through.

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

8 People are following this question.

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

Related Questions

Player's collider doesn't touch obstacle's collider every time that it collides! 2 Answers

How to mark collision point of plane and object? 1 Answer

How do I make Collider to get through another Collider? (w/o Trigger) 1 Answer

How to detect collision when Time.timeScale == 0? 2 Answers

I’m looking for a way to compare the speeds of two gameObjects on colliding. ,Hi, I’m looking for a way to compare the speeds of two gameObjects on colliding. 2 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