Strange Collision problem

Hi,

I’m new here and developing a game where I control a hand (like in the game black white) that allows me to pick up objects.
I want it not to go through the walls and floor to keep better track of it and I use the following

void OnCollisionEnter(Collision collision) {
        if(collision.gameObject.name.Equals("Sphere")){
            Debug.Log("collision happened!!");
            handSphereCollisionFlag = true;
            rigidbody.constraints = RigidbodyConstraints.FreezeAll;
        }
        
        if(collision.gameObject.name.Equals("Ground")){
            rigidbody.constraints = RigidbodyConstraints.None;
            rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
        }
        
        if(collision.gameObject.name.Equals("LeftWall")){
            Debug.Log("left");
            rigidbody.constraints = RigidbodyConstraints.None;
            rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
        }
        
        if(collision.gameObject.name.Equals("RightWall")){
            Debug.Log("right");
            rigidbody.constraints = RigidbodyConstraints.None;
            rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
        }
        
    }

And that works, but after I pick up an object (like a sphere, also with collision detection) my hand/sphere gets a velocity or force and i cant move it properly anymore. It gets a velocity or force in the x position. If I make the rigidbody kinematic, the collision detection with the walls doesn’t work anymore…
I also tried setting the velocity to zero in every frame in the FixedUpdate() but has no effect…

Any ideas how to work around this? Many thanks in advance!

I dont know if this is going to help you but I had problems with collisions in unity and what I found out is that the scale of the project can effect things that are moving fast. I believe 1 meter is 1 unit, and if your velocity is somewhat slow but the scale you are working on is really small the velocity scale in my XP will be a lot faster and stuff flys through colliders. I am not sure if this is of help to you, or if I am even on the right track but making sure things were up to scale sure helped my project collisions. Good luck… I struggled with collisions for a while until I figured this trick out.

The speed or scaling is not the issue i think, because we can make the collisions work between the hand and the floor walls. The problem is when the hand picks up the ball, i cant get rid of the applied forces. And if I make it kinematic, it can go through walls again which we want to avoid.

Any more thoughts? Many thanks in advance!

Welcome to the forum Dikken Danny!

You could try lowering the mass of the objects you are picking up. It sounds like the problem could be the added momentum of the held object. Failing that, can you post the code you are using to move the hand and pick up the objects?

I think i solved it by now: i changed the hand to a character controller and the walls to mesh colliders. If i then use the move command it no longer has the gravity issues but it still possible to have the collisions.

The documentation of the physics helped me better understand. Thanks anyway for the help!