- Home /
Collision failing on fast moving object
Given this script, I used it on a cylinder moving across a field (it is suspended in the air, without gravity influence). Four static cubic colliders act as walls, defining a simple rectangular bound. The cylinder has a capsule collider and a physics material with bounciness 1. It has a small mass (0.1) and a little drag (0.01).
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
private float x;
private float z;
public float speed=1200f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
x= Input.GetAxis("Horizontal")*speed*Time.deltaTime;
z= Input.GetAxis("Vertical")*speed*Time.deltaTime;
if (Mathf.Abs(rigidbody.velocity.x)<90&&Mathf.Abs(rigidbody.velocity.y)<90)
{
rigidbody.AddForce (x,0,z);
}
}
void Update (){
print(rigidbody.velocity);
}
}
Problem is, with speed set at 1200 (which is fast and reactive, considering the Time.deltaTime multiplayer), the collider often fails, making the cylinder pass through the wall. I tried to divide the fixed timestamp by half, with no result. The object is quite fast, but it's certainly not a bullet (it is meant to be controlled by the player), so these errors seem quite strange to me.
Is there anything else I can do to improve the collision detection? I tried to set the rigidbody parameter as Continuous Dynamic, with no results whatsoever.
Perhaps you could consider lowering the fixed timestep in Project Settings->Time a bit more, or making your object go slower in general.
Answer by haroonalam · Feb 05, 2013 at 04:37 PM
Try making Rigidbody collision detection to Continuous, go to Edit->Project Settings->Physics, make penetration lower and solver count high. Hope it may help.
I made pretty much everything and reached an almost satisfying solution. Then I tried to add another cylinder with a rigidbody to simulate a ball. Trainwreck. The ball almost always loses the collision detection. What's worse, it never recovers it. It just becomes non-collidable. A total mess :(