Choose value for speed and acceleration

This topic is 2080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I'm new to the forum.

I read about steering behaviors and I have understood a bit how the entities moves in a game (the position is updated by the velocity and the velocity is updated by the steering force).

In some examples i see that the update function of the entities has a "time elapsed" parameter that is multiplicated for the acceleration and then for the velocty. What is this parameter and is it required?

The other thing i haven't understood is how to choose an appropriate value for the max_speed and max_acceleration (or max_force). What is the relation between this two constants? Should i increase their values if i use the time elapsed parameter?

Share on other sites

In some examples i see that the update function of the entities has a "time elapsed" parameter that is multiplicated for the acceleration and then for the velocty. What is this parameter and is it required?

Yes, it is required. Imagine I tell you a car is going with a speed of 50 Km/h, and I want to know how far it has moved. If I don't tell you how long he's been going at 50 Km/h, you can't possibly know the answer. So in order to modify the position using the velocity, you need to know how long the velocity has been applied. Similarly when you want to modify the velocity using the acceleration (which is proportional to the steering force).

Share on other sites

The other thing i haven't understood is how to choose an appropriate value for the max_speed and max_acceleration (or max_force). What is the relation between this two constants? Should i increase their values if i use the time elapsed parameter?

You don't say, but I'm assuming you're simulating some sort of vehicle. Regarding max_speed and max_force, I don't know why you would necessarily need either one. The forces on the vehicle will normally come from friction. Friction forces such as wind resistance will increase with speed. Lateral tire friction (the wheels are turned) will act to steer the vehicle through a torque about the center-of-gravity. The propulsion system (e.g., car engine) will, for instance, rotate the tires and, through friction of the tires with the surface, add a force. The maximum speed for the vehicle will likely be determined by those forces, assuming you limit the maximum torque the propulsion system provides. That may be the "max_force" you're thinking about.

If so, browse the internet for information on the type of propulsion you have. If it's a car engine, look for maximum torque or horsepower data. Pick an appropriate mass for your vehicle (e.g., browse for curb-weights of various cars) and you're off to the races (pun intended).

That is, gravity, wind resistance, and tire friction will slow the vehicle. The propulsion system will provide a forward force, limited by internal friction which is some function of the engine speed* (for instance). The acceleration will be the sum of those forces times the mass. When the resistance equals the propulsive force, acceleration with be zero and the vehicle velocity won't change any more. The velocity will be zero or some maximum speed.

*Max engine torques/horsepower can be considered to reflect internal resistance.

Sorry if that's a bit wordy.

Edited by Buckeye

Share on other sites

Yes, it is required. Imagine I tell you a car is going with a speed of 50 Km/h, and I want to know how far it has moved. If I don't tell you how long he's been going at 50 Km/h, you can't possibly know the answer. So in order to modify the position using the velocity, you need to know how long the velocity has been applied. Similarly when you want to modify the velocity using the acceleration (which is proportional to the steering force).

So the time is calculated each game loop execution and passed to each update function?

Can you say me if something like this can be good?

// number of updates per second, higher = entities moves faster
fps = 100;
// for how much seconds the entities should be updated
duration = 10;

timer = new Timer(fps);
timer.start(duration);

// updates the entities until the script exceeds the duration time
while (!timer.isTimeExpired()) {
// assert the updates per seconds (fps) are not exceeded
entity.update(timer.getTimeElapsed());
}
}



Here's the timer class referred above (it is in php):

class Timer
{
/**
* @var float
*/
private $startTime; /** * @var float */ private$endTime;

/**
* @var float
*/
private $currentTime; /** * @var float */ private$nextTime;

/**
* @var float
*/
private $timeElapsed; /** * @var float */ private$lastTime;

/**
* @var float
*/
private $timeScale; /** * Constructor. * * @param int$fps
*/
public function __construct($fps) {$this->startTime   = 0;
$this->endTime = 0;$this->currentTime = 0;
$this->nextTime = 0;$this->timeElapsed = 0;
$this->lastTime = 0;$this->timeScale   = 1 / $fps; } /** * Starts the timer. * * @param float$duration
*/
public function start($duration = 1000000) { if (!preg_match('/[0-9]+?/',$duration)) {
throw new InvalidArgumentException('The passed parameter must be an integer!');
}

$this->startTime =$this->currentTime = $this->lastTime = microtime(true);$this->nextTime = $this->currentTime;$this->timeElapsed = 0;
$this->endTime =$this->startTime + $duration; } /** * @return float */ public function getCurrentTime() { return$this->currentTime;
}

/**
* @return float
*/
public function getTimeElapsed()
{
return $this->timeElapsed; } /** * @return bool */ public function isReadyForNextUpdate() {$this->currentTime = microtime(true);

if ($this->currentTime >$this->nextTime) {
$this->timeElapsed = ($this->currentTime - $this->lastTime) *$this->timeScale;

$this->lastTime =$this->currentTime;

• 15
• 21
• 20
• 11
• 9