• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Choose value for speed and acceleration

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1raxell  Members

Posted 05 February 2014 - 10:30 AM

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?

### #2Álvaro  Members

Posted 05 February 2014 - 10:35 AM

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).

### #3Buckeye  GDNet+

Posted 05 February 2014 - 11:51 AM

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, 05 February 2014 - 11:58 AM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

### #4raxell  Members

Posted 05 February 2014 - 04:34 PM

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;
$this->nextTime =$this->currentTime + $this->timeScale; return true; } return false; } /** * @return bool */ public function isTimeExpired() { return$this->currentTime > \$this->endTime;
}
}

if i add the time than the speed and acceleration constants must be higher?

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.

Sorry, i forgot to say that i'm trying to simulate a football match based on some player skills. Some of this skills are "speed" and "acceleration" represented by two constants (representing the maximum value of the skill). Each player will have a percentage of this constants.

I think speed can be interpreted as how fast a player can travel (when it has reach the max velocity), and the acceleration how much time the player take to reach the max velocity. So, if i have two players with same speed but different acceleration i expect that the player with the higher acceleration will reach the target first (correct me if i'm wrong).

So, the movements of the players should depend by its skills and not only by the enviorment (wind, ecc...).

Edited by raxell, 05 February 2014 - 04:36 PM.

### #5Álvaro  Members

Posted 05 February 2014 - 07:10 PM

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?

I didn't read your code in detail, but the best way to handle this is explained in the classic piece "fix your timestep!". You should definitely read it.

Sorry, i forgot to say that i'm trying to simulate a football match based on some player skills. Some of this skills are "speed" and "acceleration" represented by two constants (representing the maximum value of the skill). Each player will have a percentage of this constants.
I think speed can be interpreted as how fast a player can travel (when it has reach the max velocity), and the acceleration how much time the player take to reach the max velocity. So, if i have two players with same speed but different acceleration i expect that the player with the higher acceleration will reach the target first (correct me if i'm wrong).
So, the movements of the players should depend by its skills and not only by the enviorment (wind, ecc...).

Do you realize how absurd it is that you were asking us about reasonable values for max_speed and max_acceleration before we knew if your units were fish or alien spaceships?

For football players, you can probably find the 40-yard dash time for lots of them. There are also other distances available. You can also see how people that run the 100m dash accelerate (I found some cool graphs here), which you can try to match by tweaking your max_acceleration and max_velocity numbers.

Using a drag force might be a good way to limit the speed naturally, and then you only need to limit the acceleration.

In any case, playing around with different values until the response feels right for your game is the only way to go about this. And it can be a lot of fun!

Edited by Álvaro, 05 February 2014 - 07:16 PM.

### #6raxell  Members

Posted 07 February 2014 - 05:57 AM

My problem is that I have different results if I use the time elapsed or not (with the same values for speed and acceleration).

I mean the same thing of this post: http://www.gamedev.net/topic/634663-arrive-steering-behavior/#entry5003771

For example:

If I don't multiply for the time elapsed (deltaTime) I can use a value for speed like 0.7, but if I multiply for deltaTime the value must change to 70 or higher to see the player moving. But if i use a value like 70 the truncate on the velocity became needless because the velocity will never reach that value.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.