+2 votes

In pseudocode it's a method/function inside a vector that looks something like this:

```
.slide(vector) {
return vector - this * dot(this, vector);
}
```

So it's also important that in most cases you want the vector that is calling the method to be normalized (unit length), otherwise that dot product is going to be pretty huge.

Something like: norm.slide(velocity)

And for the curious, here it is in non-pseudo code: https://github.com/godotengine/godot/blob/4a4f247/core/math/math_2d.cpp#L279-L282 (but it's indeed what avencherus described).

The vector calling the method doesn't need to be normalized. The parameter is the normal and the vector will slide on its plane.

Example:

```
horizontal_velocity = velocity.slide(-gravity.normalized())
```

The normal is the up direction of the world relative to gravity which creates a horizontal plane. Velocity will be restrained by this plane so the code returns only the horizontal factor of the vector.

- All categories
- Engine 28,825