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 telltale · Jan 15, 2014 at 11:15 AM · rigidbodypassthrough

Object passing through at high speeds

Hi,

I am trying to make 3d smooth tetris. However, objects are passing through others. I created a small project to simulate this.

Project can be downloaded from: https://dl.dropboxusercontent.com/u/2118263/object-passing-through.zip

Here are the notes:

  • There is a plane, a static cube and a moving cube.

  • Static cube has position = (4.5,0.5,0), rigidbody, box collider, freeze position, freeeze rotation, no gravity and "Finish" tag.

  • Moving cube has position = (0, 0.5, 0), rigidbody, box collider, continous dynamic collision detection and Mover Script(below).

Moving cube was moving towards Static Cube, and onTrigger enter, i set the speed = 0 and log the position. The output is "Entered position @(3.6, 0.5, 0)" however I expect it to be exactly "Entered position @3.5, 0.5, 0)". Can you explain why it cannot enter the trigger exactly @3.5.

Because of this problem, I also started to think about not using collisions. Any suggestions to make a 3d smooth tetris?

Thanks.

  public class Mover : MonoBehaviour {
     
         int speed = 5;
     
         // Use this for initialization
         void Start () {
         
         }
         
         // Update is called once per frame
         void FixedUpdate () {
             rigidbody.MovePosition (rigidbody.position + Vector3.right * speed * Time.deltaTime);
         }
     
         void OnCollisionEnter(Collision other){
             if (other.gameObject.tag == "Finish") {
                 Debug.Log ("Entered position @" + rigidbody.position);
                 speed = 0;
             }
     
         }
     }
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 timcommandeur · Jan 15, 2014 at 03:30 PM 0
Share

Does the collision work on low speed?

avatar image sanmn19 · Jan 15, 2014 at 03:45 PM 0
Share

A simple solution to this would be to make the trigger(box collider) slightly bigger by 0.1. Then you can expect it to trigger at 3.5. OR Try increasing iteration solver count in the physics options. This will impact performance but I am not sure to what degree it will affect.

avatar image telltale · Jan 17, 2014 at 07:28 AM 0
Share

It works on low speed. Updating timestep will do the job, but I wanted to learn how unity works. I didn't want to make calculations to avoid it. Unfortunately as fas as I understood, I should.

1 Reply

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

Answer by Jamora · Jan 15, 2014 at 03:57 PM

Physics in games aren't contiguous like in real life (as far as we know), but discrete. This means that all physics computation is done in intervals, and these computations include collision detection. In Unity the default interval is 0.02 seconds, i.e. 50 times each second.

Now, let's imagine we have a euclidean coordinate system (x,y) and there is an object at 0,0 with a speed 1 unit/second along the x-axis. Our computation interval is two seconds, so this means we will only notice the object at points (2,0), (4,0), etc...

In Unity, the interval of physics computation can be changed in Edit -> Project Settings -> Time. It is called "Fixed Timestep". Setting that value to 0.1 or smaller will decrease the interval of computation (= CPU usage) but will allow you to notice smaller movements in your objects and possibly allow you to stop your tetris pieces in time.

Instead of using physics, I would build a tetris on a 2D grid. If you look at the tetrises of yesteryear (also lots of the modern ones), you will notice they are very blocky, which means that they too are most likely built on a grid.

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 telltale · Jan 16, 2014 at 02:55 PM 0
Share

Is there a collision detection default interval? Or do you mean Time$$anonymous$$anager.fixedTimestep? I wanted to be sure, because the default value of fixedTimestep is 0.02.

avatar image Jamora · Jan 16, 2014 at 08:21 PM 0
Share

Fixed timestep is the interval at which all physics computation is done. You're correct, the default timestep is 0.02; I missed a zero.. guess it's time to get glasses =/.

The point is, that halving that value will double the physics computation and will allow you to detect smaller penetrations. I still recommend a 2D grid to allow for precision positioning of the blocks. Using Unity's physics (I think it's PhysX)for anything precise seems like a bad idea to me.

There is no Time$$anonymous$$anager.fixedTimestep in the Unity API, but there is Time.fixedTimestep. Time.fixedTimestep is the same value as the one in Edit -> Project Settings -> Time -> Fixed Timestep.

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

21 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

Related Questions

Detect a GameObject Passing Between Other Two GameObjects? 4 Answers

Character Controller vs moving platform 0 Answers

Detecting which Collider involved in Trigger 'Collision' 4 Answers

box colliders with rigidbodies passing through each other 0 Answers

AddExplosionForce doing nothing? 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