Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to collide objects with high speed in Unity

I try to create game for Android and I have problem with high speed objects, they don't wanna to collide.

I have Sphere with Sphere Collider and Bouncy material, and RigidBody with this param (Gravity=false, Interpolate=Interpolate, Collision Detection = Continuous Dynamic)

Also I have 3 walls with Box Collider and Bouncy material.

This is my code for Sphere

function IncreaseBallVelocity() {
rigidbody.velocity *= 1.05;
}

function Awake () {
rigidbody.AddForce(4, 4, 0, ForceMode.Impulse);

InvokeRepeating("IncreaseBallVelocity", 2, 2);
}

In project Settings I set: "Min Penetration For Penalty Force"=0.001, "Solver Interation Count"=50

When I play on the start it work fine (it bounces) but when speed go to high, Sphere just passes the wall.

Can anyone help me?

Thanks.

Edited

var hit : RaycastHit;

var mainGameScript : MainGame;

var particles_splash : GameObject;

function Awake () {
rigidbody.AddForce(4, 4, 0, ForceMode.Impulse);

InvokeRepeating("IncreaseBallVelocity", 2, 2);
}

function Update() {
if (rigidbody.SweepTest(transform.forward, hit, 0.5))
    Debug.Log(hit.distance + "mts distance to obstacle");
if(transform.position.y < -3) {
    mainGameScript.GameOver();
    //Application.LoadLevel("Menu");
}
}

function IncreaseBallVelocity() {
rigidbody.velocity *= 1.05;
}

function OnCollisionEnter(collision : Collision) {
Instantiate(particles_splash, transform.position, transform.rotation);
}

EDITED added more info

  1. Fixed Timestep = 0.02 Maximum Allowed Tir = 0.333
  2. There is no difference between running the game in editor player and on Android
  3. No. It looks OK when I set 0.01
  4. My Paddle is Box Collider without Rigidbody, walls are the same
  5. There are all in same layer (when speed is normal it all works) value in PhysicsManager are the default (same like in image) exept "Solver Interation Co..." = 50
  6. No. When I change speed it pass other wall
  7. I am using standard cube but I expand/shrink it to fit my screen and other objects, when I expand wall more then it's OK it bouncing
  8. No. It's simple project simple example from Video http://www.youtube.com/watch?v=edfd1HJmKPY
  9. I don't use gravity
like image 498
Kec Avatar asked Jan 14 '13 20:01

Kec


People also ask

Do you need rigidbody for collision Unity?

In Unity3D, you need rigidbodies on GameObjects that use colliders, as they use physics. You don't need rigidbodies on static GameObjects because they don't use physics, though you still need to have at least one in the calculation.

What is the difference between collision and trigger Unity?

An easy way to differentiate between the two is to think of them visually. OnCollisionEnter can be visualized as colliding against a wall, and OnTriggerEnter can be visualized as triggering an alarm. Let's take a look at them individually.

What is discrete collision in Unity?

For dynamic objects (i.e. objects with Rigidbody ) that don't touch fast-moving objects at all, you can safely use Discrete collision. For dynamic objects that are not fast-moving, use Continuous collision on them if you need them to always collide with fast-moving objects.


1 Answers

See:

  1. Similar SO Question
  2. A community script that uses ray tracing to help manage fast objects
  3. UnityAnswers post leading to the script in (2)

You could also try changing the fixed time step for physics. The smaller this value, the more times Unity calculates the physics of a scene. But be warned, making this value too small, say <= 0.005, will likely result in an unstable game, especially on a portable device.

The script above is best for bullets or small objects. You can manually force rigid body collisions tests:

public class example : MonoBehaviour {
    public RaycastHit hit;
    void Update() {
        if (rigidbody.SweepTest(transform.forward, out hit, 10))
            Debug.Log(hit.distance + "mts distance to obstacle");

    }
}
like image 167
Jerdak Avatar answered Oct 26 '22 13:10

Jerdak