In this scene I have the circle casting it’s collider shape to the left and returning a value if anything is hit. But as you can see it stops detecting the square as soon as it overlaps with it. How can I make it so it continues to detect objects even when they’re overlapping?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test2 : MonoBehaviour
{
public float moveSpeed;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Rigidbody2D rb = GetComponent<Rigidbody2D>();
RaycastHit2D[] hitResults = new RaycastHit2D[1];
int numberHit = rb.Cast(Vector3.left, hitResults, moveSpeed);
if (numberHit > 0)
{
print("Hit " + numberHit + " colliders.");
for (int i = 0; i < numberHit; ++i) print("Hit this: " + hitResults[i].collider.name);
}
if (numberHit == 0)
{
print("Nothing hit!");
}
}
}