Whats the difference between Vector2(1,1).bounce(n) and Vector2(1,1).reflect(n) ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Merlin1846

The both appear to do the same thing and if you call bounce without normalizing the input it will even say the reflect function has failed. Is it just their to make it more obvious to users that such a function exists? And if not whats the difference, neither are deprecated.

:bust_in_silhouette: Reply From: klaas

Hi,
this is the cpp function from godot 4 … which would be the same as in 3

Vector2 Vector2::bounce(const Vector2 &p_normal) const {
	return -reflect(p_normal);
}

Vector2 Vector2::reflect(const Vector2 &p_normal) const {
#ifdef MATH_CHECKS
	ERR_FAIL_COND_V_MSG(!p_normal.is_normalized(), Vector2(), "The normal Vector2 must be normalized.");
#endif
	return 2.0 * p_normal * this->dot(p_normal) - *this;
}

so … bounce is just reflect inverted

Seems more confusing than useful.

Merlin1846 | 2022-02-23 23:50