The diagrams on this page might not be 100% acurate, they are just meant to illustrate.

This is meant to help to move in Byte Arena's realistic world simulation, where physics works just the same as in real life.

We use vectors to model physical forces. They point into a direction and indicate a force. Arithmetic on vector is particularly useful in realistic movement engine, we will see why later.

Your agent has a certain mass, if the mass is in movement we say that it has a velocity. It represents its current force.

We also model it as a vector.

- A vector is represented by
`(x, y)`

- \(\vec c\) is the vector named
`c`

- \(∥c∥\) is the magnitude of \(\vec c\)
- The agent is always placed at the origin
`(0, 0)`

and \(\vec c\) defines its velocity - \(c_1\) represents the
`x`

axis of \(\vec{c}\) - \(c_2\) represents the
`y`

axis of \(\vec{c}\)

`desired vector`

In autonomous vehicule there is a notion called `desired vector`

, it's just the direction (and force) in which your agent wants to go.

For example, if you need to go to the left, your agent's desired vector will point to the left.

We call it a desire because you might have other forces applied to your agent, the velocity is one.

In this case, your agent is in front of two obstacles (one on the right and one on the left) and you need to pass in the middle of them.

Using vectors is simple, the formula is the following: $$\begin{align*} \vec{c} &= \vec{a} + \vec{b} \\ \vec{c} &= \begin{Bmatrix}a_1 + b_1\\a_2 + b_2\\\end{Bmatrix} \end{align*}$$

`arriving`

techniqueImagine you want to stop at a desired position.

At this point of the article you would probably send the desired vector at full magnitude in direction of that point. Let's try it! You will notice that once the point has been reached by your agent, depending of your current speed and \(\vec velocity\) you will end up after the point.

Your agent will then send the opposite vector to reach the point again, and so on. It will end once the physics has reduce your velocity enough due to friction, but that is probably going to take some time.

Given the fact that you won't be able to stop immediatly once you reached the desired point, you will need to use a technique called `arriving`

.

This technique consist of reducing your \(\vec velocity\) (and thus speed) before actually arriving to the point.

`p`

is the point you want to reach.

\(\vec c\) is the velocity of the agent.

\(\vec d\) is the desired direction.

`t`

is the point where you need to reduce your velocity (it was set arbitrarily). We are going to reduce the desired \(\vec velocity\) by dividing it by 2.

$$
\vec{c'} = \vec{d} - \vec{c} \\
\begin{equation}
∥c'∥ =
\begin{cases}
\vec c, & \text{if}\ \vec{c} < t \\
\vec c / 2, & \text{if}\ \vec{c} >= t
\end{cases}
\end{equation}
$$

Byte Arena provides an official implementation of a two dimensional vector written in JavaScript, you can find it here: bytearena-sdk-vector2.

© XTUC SAS

N° SIRET : 821 797 891 00016, RCS Strasbourg TI 821 797 891