Browse Source

Fix Vector's Bounce Reflect

Fixes Vector 2 and 3 bounce and reflect methods to match gdscript

Co-Authored-By: Bruno Campos <[email protected]>

Move calculation to reflect

fix commit

squash

fix style
NHodgesVFX 5 years ago
parent
commit
a2e6f7a5ef
2 changed files with 4 additions and 4 deletions
  1. 2 2
      include/core/Vector2.hpp
  2. 2 2
      include/core/Vector3.hpp

+ 2 - 2
include/core/Vector2.hpp

@@ -180,8 +180,8 @@ struct Vector2 {
 		return -reflect(p_normal);
 		return -reflect(p_normal);
 	}
 	}
 
 
-	inline Vector2 reflect(const Vector2 &p_vec) const {
-		return p_vec - *this * this->dot(p_vec) * 2.0;
+	inline Vector2 reflect(const Vector2 &p_normal) const {
+		return -(*this -p_normal * this->dot(p_normal) * 2.0);
 	}
 	}
 
 
 	inline real_t angle() const {
 	inline real_t angle() const {

+ 2 - 2
include/core/Vector3.hpp

@@ -238,8 +238,8 @@ struct Vector3 {
 		return v;
 		return v;
 	}
 	}
 
 
-	inline Vector3 reflect(const Vector3 &by) const {
-		return by - *this * this->dot(by) * 2.f;
+	inline Vector3 reflect(const Vector3 &p_normal) const {
+		return -(*this - p_normal  * this->dot(p_normal) * 2.f);
 	}
 	}
 
 
 	inline Vector3 rotated(const Vector3 &axis, const real_t phi) const {
 	inline Vector3 rotated(const Vector3 &axis, const real_t phi) const {