How to check Hypothetical Collisions in 2D

Hey guys -
I’m coming in from Game Maker, and having some friction making the transition.

In Game Maker, you have a function called place_meeting(x,y,object) that returns true if the game object calling it WOULD collide with the argument object at the specified argument coordinates.

This was great for ensuring that stuff wouldn’t get stuck into walls.

For example:

if (place_meeting(x+vX,y,object) {

//Increment x until place_meeting(x+1,y,object) - will push the object right up to another without mashing them into one another

}

Is there a similar function in Unity/Unity2D? I’m doing some reading on the Collision events, but it seems like those only handle collision that happen THAT frame, rather than hypothetical collisions.

Any help appreciated.

1 Answer

1

Did you ever find out? I’m wondering the same thing.

The only thing I can think of is to try a raycast of some kind. And as long as everything is set up correctly, I haven't experienced much issue with the 2D collision. If you're literally worried about objects getting stuck together, this post helped me: http://answers.unity3d.com/questions/794668/2d-character-controller-getting-stuck-on-walls.html