CSE557
Final Project
Bumper
Cars
By Ryan Kaminsky & Lynn Yang
Our project is to simulate the game "bumper cars" using both
player-controlled and computer-controlled cars. We simulated the cars as a
particle system and used a physics engine to control the movement of the cars
and the collisions between the cars and the arena boundry. We also
developed several strategies that can be assigned to computer-controlled
vehicles enabling them to play the game more intelligently and creating some
interesting interactions between different cars and different
strategies.
The main components of the system are as follows:
CARSCar
Attributes
A number of state attributes are maintained on
each vehicle to create smooth movement based on the physics of the
system.
Position: This is the current 3D position of
the car in the drawing window. For the purpose of this game, cars can only
move in two directions, but the overall view of the game appears as if in
3D.
Heading: At creation time, a randomly assigned heading
unit vector is assigned to each car. This is the direction vector along
which a car can accelerate or decelrate. To enable more realistic car
movement, a car can only steer in a direction tangent to its
heading.
Velocity: The current speed and direction of a car
at a moment in time. This is updated based on the forces acting on the
car at each moment in time.
Score: The accumulated
score based on the number of other cars bumped. A car's score is increased
if the point of contact is within a threshold distance of the car's heading and
the score is decremented if the contact is elsewhere.
Mass:
The mass of the car. This is used to compute the resulting forces
acting on the car.
Strategy: The strategy the car
follows while playing the game.
Forces
There are a number of forces acting
on the cars during the course of the game. These forces affect their
movements and act according to the general rules of Physics.
Acceleration/Deceleration:
Acceleration is under the
control of the car itself. The user controls the accelration using the up
and down arrow keys and the computer-controlled cars use acceleration depending
on the strategy. We chose to make all cars have the same acceleration
ability, meaning that the true acceleration is inversely proportional to mass.
Lower mass cars can accelerate faster than higher mass cars. The
resulting acceleration is a=F/m (force/mass).
Steering
force:
Steering force is also under the control of the car itself.
The steering force is used to change the direction of the heading for a
car. Once the heading is changed, the car can accelerate along the new
heading, thus moving in the correct direction. This is similar to the way
a car steers.
The relationship between the acceleration/deceleration
and steering forces and the car heading is illustrated in the
image below:
<!--[if
!vml]-->
<!--[endif]-->
Friction:
Friction
force is imposed on the particle system and simulates the friction caused by the
contact of wheels with the surface of the bumper arena and is proportional to
the velocity of the car. The friction force is separated into two
directions that each exert different forces:
1. The first component
of the force is in the direction of the car heading. This friction force
exerts a force that is opposite the velocity vector in this direction and
a fraction of the car speed. A friction force of 0 will cause the
cars to move indefinitely, while a large force will cause the cars to barely
move.
2. The second component is tangent to the car heading.
To make the movement of the bumper cars appear more realistic, the
friction force tangent to the car heading is set to be extremely high.
This simulates the fact that a car drives on wheels and moving in a
direction tangent to the direction of the wheels is a rare occurrence unless the
car slides due to a severe loss of friction (from rain or ice).
The
friction components are illustrated below. The velocity has components in
both the heading direction and the direction tangent to the heading. Thus,
the velocity component tangent to the heading will decreasing much more rapidly
than the other velocity component.
<!--[if
!vml]-->
Collisions
Car
Collisions
We consider the collisions as perfectly
elastic, frictionless and ignore the rotation of the cars. The
collisions will behave as if all the mass of the car is concentrated at the
car's center of mass, which is the sphere center. Then, we apply the
conservation laws of momentum and energy during the collision.
We use the
following equations, derived from Newton's Laws, to calculate
the velocity of car A and car B after the collision.
v(A) and v(B) are
velocities of car A and car B before collision, respectively.
v(AB) is the
their relative velocity.
m(A) and m(B) are masses of car A and car B,
respectively.
n is the vector pointing from the position of car A to the
position of car B.
<!--[if
!vml]-->
<!--[endif]-->
<!--[if
!vml]-->
<!--[endif]-->
The figures below
show a two-dimensional elastic collision between a moving car and a
stationary one.
<!--[if
!vml]-->
<!--[endif]-->
When two cars hit each
other, the velocity of a car can be considered as the sum of two
component- the component vertical to the common normal surfaces of the colliding
bodies at the point of contact, and the component along the common normal
surface. In the figure above, the velocity of the object (represented by
red arrow) is considered as the two component represented by blue
arrows.
<!--[if
!vml]-->
<!--[endif]-->
When a collision takes
place, the two-dimension collision can be considered as a one-dimension
collision in the direction vertical to the common normal surfaces, and both
object maintains their velocity in directions along the common normal
surfaces.
<!--[if
!vml]-->
<!--[endif]-->
After the
collision, the objects move away along their new velocities.
This
collision calculation can be generalized for the cases where two or more
colliding objects are moving.
Wall
Collisions
For collisions with the surrounding walls,
we also assume a perfectly elastic collision. In this scenario,
we use the negative of the component of the velocity that is vertical to
the wall as the new velocity.
Strategies
We have created a number of
strategies that the computer-controlled opponents follow. Each strategy
has a particular goal that the computer-controlled car is attempting to achieve.
Often these goals involve targeting a specific car, or a specific type of
car.
The key below shows the various strategies as well as the
colors associated with them.
<!--[if
!vml]-->
<!--[endif]-->
1. Chase
the closest car: Here, the car will constantly analyze the playing
area to determine the closest car. It will then adjust its steering and
acceleration to bump this target.
click
here to see the video
2. Avoid the closest car:
The car will analyze the playing area to find the closest car, then it
will direct itself away from that car.
click
here to see the video
3. Chase the easiest hit:
Different from the first strategy, strategy three chooses its target
by considering both the distance and the heading direction of the other cars
The closer a car is and the more favorable its heading, the better the
chance it will be chosen. The strategy car will then adjust its steering
and acceleration to bump this target.
We use a measure of possibility to
determine the likelihood that a target car can be hit by the strategy
car:
PossibilityMeasure = cos(a) / d;
a is the angle difference of the
heading direction of the car and the position difference of the two cars;
d
is distance between the two cars.
click
here to see the video
4. Avoid the easiest hit:
The possibility measure of strategy 3 is used, but the strategy car will
then avoid this target rather than chase it.
click
here to see the video
5. Careful Driver: This
strategy is a troublemaker. The car drives around and gets close to other
cars and walls, but almost never hits them. This strategy just likes to
scare people.
click
here to see the video
6. Chase the car with the lowest
score: For this strategy, a car will analyze the playing field for the
car with the lowest score and then adjust its parameters to help it bump that
target.
click
here to see the video
7. Chase the car with the highest
score: This strategy is similar to strategy 6, but will find the car
with the highest score instead of the lowest.
click
here to see the video
8. Chase the user: For this
strategy, the car will only focus on bumping the user car and will adjust its
parameters to enable it to do so.
click
here to see the video
9. Avoid the user: This
strategy is similar to strategy 8, but instead of moving towards the user, it
will move away from the user.
click
here to see the video
10. Sneaker: This car will
look for cars within a particular radius that are facing the opposite way, so it
can sneak up and bump them from behind without them knowing.
click
here to see the video
Other videos:
Mass
effects: Demonstrates some of the mass effects of the system.
200
cars: Demonstrates the system with 200 bumper cars trying to bump each
other.
Runaway
strategies: Demonstrates the difference between some runaway
strategies.
other
Application
Features
Here is a screenshot of our application. Additional
features include, the drawing of the car number and car score over each car, a
legend that describes the strategies and a debug window that displays car
attributes (velocity, position, mass, etc.) when a car is clicked on.
New cars can be added with a chosen strategy and mass, by using the add
car feature. For debugging, a white line from the car to its target can
be drawn.
<!--[if
!vml]-->
<!--[endif]-->