Topic
  • 1 reply
  • Latest Post - ‏2013-12-17T14:26:37Z by TomBanks
ecj2676
ecj2676
1 Post

Pinned topic Braking in simple car

‏2013-12-15T13:45:26Z |

Hello, all. I am working with lfranchi, who posted here about a month ago, on using CodeRally in an AP computer science class. As I was building some cars for myself, I realized that my cars are not slowing down when I apply the brakes. I am applying brakes by calling getCar().setBrakePercent(100). I wrote a very simple car to demonstrate the issue. I set up an advanced car with 1/1/1/1 for the 4 attributes (so 25% in each category) and run a race on the figure 8 track with the implementation below. The behavior I see is that the car doesn't start itself (as expected), but if another car bumps into it, it starts moving (as expected) and never slows down (not expected!). It will steer itself all the way around the track (as expected), but only changes speed if something bumps into it. Braking never has any effect.

Here's the code... any advice about why braking doesn't seem to be working would be much appreciated.


public 
class Frank 
extends DefaultCarAI {

  // aim at the next checkpoint and try to stop

 public 
void onCheckpointUpdated(CheckPoint cp) {
    getCar().setTarget(getCar().getCheckpoint().getCenter());
    getCar().setBrakePercent(100);
  }

  // aim at the first checkpoint and try to stop

 public 
void onRaceStart() {
    getCar().setTarget(getCar().getCheckpoint().getCenter());
    getCar().setBrakePercent(100);
  }

  // try to stop

 public 
void onTimeStep() {
    getCar().setBrakePercent(100);
  }


 public 
void onObstacleCollision(Obstacle obs) { }

 public 
void onObstacleInProximity(Obstacle obs) { }

 public 
void onOffTrack() { }

 public 
void onOpponentInProximity(Car car) { }

 public 
void onStalled() { }

 public 
void onCarCollision(Car car) { }
}

 

  • TomBanks
    TomBanks
    66 Posts

    Re: Braking in simple car

    ‏2013-12-17T14:26:37Z  

    Hi!

    Those are some very interesting results. The way that braking currently works isn't perfect - when you increase the brake percentage you increase the car's drag in the physics engine (as opposed to actually braking). It seems that this means that there is a minimum speed that the cars can have where due to rounding and whatever else the drag forces applied to the vehicle don't actually slow the car down. Without doing more debugging I would also want to look at if the drag is related to the cars' acceleration (as the acceleration is 0 that may have an effect).

    It is in plan to have a look at the braking mechanic to correctly model the braking - I'll increase the priority as it's clear that the drag braking isn't working properly at lower speeds.

    Thanks for raising this,

    Tom