- Home /
How to park completely?
Hello,
I am developing a car parking game. But I couldnt find a function like "encapsulate(hedef : GameObject) ?" that knows when car is comletely on targer. Can anyone show me which function do I use so that Levels should finished.
Thanks
Answer by robertbu · May 03, 2013 at 02:20 PM
If your parking places are axes aligned, you can test the eight points of the mesh bounds against the bounds of the box collider for the parking space.
http://answers.unity3d.com/questions/8688/local-bounds-or-not-aabb-bounds.html
Another solution would be to place a box collider on the surface of each parking space with a unique name. Raycast down from the four corners of the car. If all four raycasts hit the same collider, then the car is parked in the space.
Answer by Itinerant · May 03, 2013 at 04:08 PM
I'll give a third methodology, which may work for you. Test for rotation of the car, to make sure it's straight. Then test the base point of your car model and see it it's within an acceptable area. Ie, if the base point of the car is right in the middle, there might be a possible 'window' of 1m x 2m that the car could reasonably fit into.
I'd probably set the car to make a single raycast straight down, then an invisible plane in the bottom of each parking spot that's the size of the 'window'. I'd pull rotation data from that plane, so that the parking spaces can be any orientation without recoding anything.
Note that you'll need to make a range of possible rotations, too. $$anonymous$$aybe it can be within 5 degrees of straight, or something like that.