I'm looking for simple car parking algorithm for a game.
The positions of car and garage each defined by 3 numbers (x, y, theta)
. Where x
and y
- center of the object and theta
- angle between the object axis and the X axis.
The car movement is simplified - it's a dot (no need to calculate exact tire movement) that can drive with fixed speed
back and forward or turn following a circle with the radius R
(the turning radius could be fixed or flexible - doesn't matter - any option would be fine for me) and it has no inertia or acceleration
.
The garage has 3 walls that shouldn't be touched by the car. It's possible to use exact dimensions for collision, but for simplicity the collision checked by measuring the angles between car and garage and the distance between car axis and the garage center. When car and garage are close enough (distance between centers is less than some constant CloseEnough
) the collision checked by (alpha, d) < (maxAlpha, maxDistance)
The world simulated by ticks, we take the current car controls - moving direction
forward or backward and the turning angle
and calculate the car next position.
The algorithm should produce series of control commands, like [forward, left], [forward, left], [backward, straight], [forward, right]
.
It's ok if it will be iterative and produce one command at a time - then check what's going on on the next tick and produce another one. It can ask the simulation engine to simulate and produce new coordinates given the control command or use simulation engine to try multiple options and choose the best one.
Also it's ok if it does it by series of approximated movements, like it tried once - missed, tried another time - get closer, and third time - finally parked (but it should be more or less reasonable and don't do tens or hundrends of back and forth iterations).