CollisionEnter and Collision Exit won't work
I have a triangular prism, set to rotate around pivot point all around the object when that direction is chosen, thus rolling the object. The game starts with a few of these pivot points (with sphere colliders, not set to trigger) in contact with the ground with tag "TriangleTiles".
Essentially if the prism (with child of pivot points) has pivot points in collision with the ground triangle tiles, I want those specific pivot points added to a List so I can use them in my movement script where my prism with roll perfectly on specific blocks.
The tiles have convex mesh colliders, as I made these tiles in Blender.
Here is my collision code, attached to each pivot point game object.
public class PivotPointCheck : MonoBehaviour
{
private TriPrismMovement TriPrismMovementScript;
void Start()
{
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "TriangleTile" && !TriPrismMovementScript.PivotPoints.Contains(this.gameObject))
{
TriPrismMovementScript.PivotPoints.Add(this.gameObject);
}
print(this.gameObject.name);
}
private void OnCollisionExit(Collision collision)
{
if (collision.gameObject.tag == "TriangleTile" && TriPrismMovementScript.PivotPoints.Contains(this.gameObject))
{
TriPrismMovementScript.PivotPoints.Remove(this.gameObject);
}
}
}
When the game starts, no collision is recorded whatsoever, any help is appreciated!
Answer by streeetwalker · Mar 24, 2020 at 04:37 PM
@Kastor438, the pivot points and your ground have RigidBodies on them and all are non-Kinematic? (Is Kinematic unchecked on all objects).
Answer by Kastor438 · Mar 24, 2020 at 08:27 PM
@streeetwalker no, neither have rigidbodies, As far as I know I shouldn’t need them, do I require rigidbodies to detect collisions?
yes, to get a collision on two object both must have RigidBody components. And they both must be non-Kinematic.