I am new to Unity and have been trying to make a game where a robotic arm + gripper can perform household tasks.
I have a object in a kitchen setting and I have a food object sitting on a kitchen counter( which has a Box Collider), however when the arm moves through the kitchen counter is breaks apart and the whole thing glitches forcing me to reset the level. To fix this, what I found online said that making the counter a trigger would allow the arm to move through the kitchen counter with no issues. This worked, the arm no longer glitches out when entering the counter space.
However now the issue is that now that the counter is a trigger, how do I make it apply a normal force so that objects can sit on top of it, such as a food item? I have tried the following script but the objects fall through immediately.
Thanks so much for your time and help!
using UnityEngine;
public class CounterTop : MonoBehaviour
{
void onTriggerStay(Collider other)
{
if(other.attachedRigidbody)
{
other.attachedRigidbody.AddForce(Vector3.up * 20);
}
}
}
Changing the counter top collider to a trigger collider is definitely not the way to go. Triggers are meant to allow collision detection without involving physics collisions. You WANT the counter top to involve physics collisions. Specifically, you want the counter top to provide support for food collider rigidbodies that lay on top of it and to prevent your arm from going through it.
Without knowing how your kitchen arm is configured, its hard to say what the problem is.
What are the scripts attached to your arm?
I have motor scripts attached to each joint of my arm to simulate the servo motor applying a torque to each joint controlling the rotation of the forearm and wrist in different directions as well as controls the gripper opening/closing. All segments of the arm have rigid body component and configurable joints.
I was thinking of 2 possible options:
First 1 being, adding a common tag to the objects that I want to be able to physically interact( i.e. sit on top) with the counter. And so in my onTriggerStay() function I could only apply force if the colliding rigidbody had that tag.
or idea 2 is, not making the counter a trigger and just leave it as a collider and so then all food items ( which have mesh colliders) should sit on top of the counter fine and then just add a collision detection script specifically for the arm. The issue is is that my arm doesn’t have collider components since it’s okay for it to go through things I just want to prevent it from glitching when it does.
I’d go with idea 2. Also, if you don’t want the arm to collide at all with something, you can set it in the Physics options under Edit > Project Settings. Go down to layer collision matrix and uncheck the layers you don’t want to interact. That is a way to prevent the arm from colliding with the counter. Just reassign the layers for each and you good.
However, I am still curious about why it is glitching out in the first place. Here is some stuff you can try on your arm.
On the rigidbody of each joint and parent rigidbody:
Set ‘Interpolate’ to Interpolate
Set ‘Collision Detection’ to Continuous
On each joint:
Make sure connected body is correctly assigned
Make sure break force/torque is Infinity
If this doesn’t help, post your motor code. Could be because of that.