Hi all,
have a problem and can’t figure it out.
I have:
-
moving platform
-
character controller player object
-
box object which is destroyed on collision with player
Both box and player become platform children to move along with it. But once box becomes platform child it stops detecting a collistion with player.
This is collision detection code from the box script:
private void OnCollisionEnter(Collision other)
{
if (other.collider.TryGetComponent(out PlayerController player))
{
Collected.Invoke();
GameManager.Instance.CollectedBoxesCount++;
Destroy(gameObject);
}
if (other.gameObject.GetComponentInParent<MovingPlatform>() != null)
{
transform.parent = other.transform;
}
}
Please let me know what am I doing wrong.