The docs for this function are kinda poor, and I'm having a hard time finding any example out there. The docs read:

void set_axis_velocity ( Vector2 axis_velocity )

Sets the body's velocity on the given axis. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.

From this description I assumed that axis_velocity.x is a rotation that defines our axis, and axis_velocity.y is a scalar that defines our speed in that direction. However, I believe my assumption was incorrect. When I use set_axis_velocity it seems to behave nearly identically to set_linear_velocity.

Digging into the engine code, we have this:

void RigidBody2D::set_axis_velocity(const Vector2 &p_axis) {
	Vector2 axis = p_axis.normalized();
	linear_velocity -= axis * axis.dot(linear_velocity);
	linear_velocity += p_axis;
	PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY, linear_velocity);
}

I'm still confused about what this accomplishes. Can someone help me understand what this function is doing and why?

Thanks!

From looking at the code, it seems that the set_axis_velocity() function is used to set the linear velocity of a body along a specified axis. The p_axis parameter is expected to be a normalized Vector2, and the resulting linear velocity is the projection of the linear velocity onto that axis, plus the length of the vector. This can be useful for limiting movement along certain axes—for instance, in a platformer or jump game, you could use this to make sure the player only moves along the x-axis when on the ground, and along the y-axis when in the air.

Yeah, I don't see the point of this function. You can set linear_velocity directly, just .x or .y if you want, and for rotation you can set angular_velocity directly. And none of this has changed from 3.x to 4.x.