I have a large tile map that I stream dynamically. I am trying to create a collision system that works off of the tile data in the tile map(whether a tile is solid or not) instead of dynamically loading colliders for tiles on the screen. What I would like to do is test if where the player is moving to is going to be inside of a tile or not(i.e a collision) and if it is then stop the movement. But I cannot seem to find out how to “test” this kind of translation before actually committing the translate.Here is my current movement code.
private void Update() {
float horizontalAxis = Input.GetAxis("Horizontal");
float verticalAxis = Input.GetAxis("Vertical");
if (Mathf.Abs(horizontalAxis) < axisThreshold)
horizontalAxis = 0;
if (Mathf.Abs(verticalAxis) < axisThreshold)
verticalAxis = 0;
Vector2 input = new Vector2(horizontalAxis, verticalAxis).normalized;
if (input != Vector2.zero)
{
//want to check if colliding with a boudning box here
_transform.Translate(input * speed * Time.deltaTime);
}
}