Collider and design level help

Hello everyone…

I am making car race game in 2d.

my path is like this :

I have path like this. Car will run on this path.

Now i am confused about how do i make colliders so that car does not go out of this path. I dont want to allow my car to go outof this path.

If car collides with path boundary then game will be over.

I need some idea regarding this. Please help me guys.

Thanks.

2 Answers

2

As per my suggestion you have to use Edge Collider 2D here.
For above path you have to create three colliders and using Edge Collider you don’t have worry about curve shapes.

EDIT:
3 Colliders

  1. Outer boundry
  2. Inner circle boundry
  3. Inner square boundry

Ohw its 2d, missed like the first line or something XD I was wondering why you would suggest an edge collider.

Based on game type after seeing path image, it become clear that she has to create perfect path otherwise car stuck at edges.

3 colliders means?

ok but how will i create whole outer boundary using edge collider ? I need take num of objects with edge collider. is it so ?

No single Edge Collider become enough here. You have to first study about this collider type then implement.

What I would do is make an empty game object called (invisible wall) and make some extra game objects as child of that invisible wall game object depending how many colliders I need which are spread out outside the path.

give each child game object a box collider, scale it and place it on the side of the path where you don’t want the car to go.

if you placed the game objects with the colliders all around the path, you should be good to go.

write a script saying:

void OnCollisionEnter(Collision col)
{
    if(col.CompareTag(Car))
    {
        //do something.
    }

}

put it on the child game objects…

java probably looks similar.

there is probably a more efficient way so play around with it.

I hope this helps.

ok. But what about that curve ?