Project 1d - Control acceleration of second runner, Detect skidding, Skid motion
Goal: The goal of this phase of the project was to create a second runner that is controlled by the player. The human player will use the mouse to determine the acceleration and turn radius of the vehicle. The camera will be attached to the human controlled car so there can be a competition between him and the computer's car. The program will detect when the human car accelerated too fast and apply friction, which simulates the skidding of the vehicle.

System: My project was written on Windows XP using Processing ( The Java wrapper used by Processing should make it cross-platform compatible.

Second Car: My first step was to call drawr3DCar() a second time to draw another car primitive at the center of the screen. I then proceeded to draw everything else, performing the rotations and translations so each object was relative in relation to the center of the screen. This had the affect of "attaching" the camera to the green human controlled car.

Car Control: For my car control I simply use the mouse position on the screen to determine forward acceleration and turn amount. I keep track of the car's position and direction in a global variable, and update those variables at each step using a function that takes in mouseX and mouseY and multiplies it by a constant. I had to use some trial and error to determine what constants provided a "realistic" driving experience. Unfortunately I did not have time to implement reverse.

Skidding: To detect skidding I calculate the acceleration of the previous step of the car (using the points p2[x|y]_before). I then calculate the acceleration of the human car using the same method as the computer controlled car. If the acceleration is too high then place a restriction on how much the driver can accelerate further.

Applet Instructions:
Drag the vertices to edit the track.
Drag midpoints (small dots) to create a new vertex.
Press 1 to enable editing mode.
Press 2 to enable 2D racing mode.
Press 3 to enable 3D racing mode.
Press UP ARROW or DOWN ARROW in racing modes to change the camera angle.
Press LEFT ARROW or RIGHT ARROW in racing modes to change the camera distance.
Press + or - in editing mode to create less or more interpolated curves.
Use your mouse to control the car. Up/Down = Acceleration. Left/Right = Turn.

To view this content, you need to install Java from

Source Code: p1d.pde

Demo Video: p1d-demo-divx.avi (5.6 MB, DivX Required)

Demo Pictures:
(click to enlarge)

The green human controlled car racing the red computer controlled car.

Copyright Info :: W3C :: CSS