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!