From d0130b79680ffb873b56eafbb689aaaafa1ac2b3 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 6 Dec 2024 11:42:31 +0100 Subject: bug fox --- src/crepe/system/CollisionSystem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index f75d0ad..fe2d669 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -191,7 +191,7 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal } Direction resolution_direction = Direction::NONE; - if (resolution.x != 0 && resolution.y > 0) { + if (resolution.x != 0 && resolution.y != 0) { resolution_direction = Direction::BOTH; } else if (resolution.x != 0) { resolution_direction = Direction::X_DIRECTION; @@ -306,7 +306,7 @@ void CollisionSystem::determine_collision_handler(CollisionInfo & info) { if (info.this_rigidbody.data.body_type == Rigidbody::BodyType::STATIC) return; // If second body is static perform the static collision handler in this system if (info.other_rigidbody.data.body_type == Rigidbody::BodyType::STATIC) { - static_collision_handler(info); + this->static_collision_handler(info); }; // Call collision event for user CollisionEvent data(info); -- cgit v1.2.3 From cc320c87372dfbcce5f1cee66397466d90a9ba0a Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 6 Dec 2024 12:31:38 +0100 Subject: removed minus one from calculation --- src/crepe/system/CollisionSystem.cpp | 4 ++-- src/example/game.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index fe2d669..bde217f 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -512,7 +512,7 @@ bool CollisionSystem::get_box_circle_collision(const BoxCollider & box1, float distance_squared = distance_x * distance_x + distance_y * distance_y; // Compare distance squared with the square of the circle's radius - return distance_squared <= circle2.radius * circle2.radius-1; + return distance_squared <= circle2.radius * circle2.radius; } bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1, @@ -533,7 +533,7 @@ bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1 float radius_sum = circle1.radius + circle2.radius; // Check if the distance between the centers is less than or equal to the sum of the radii - return distance_squared <= radius_sum * radius_sum - 1; + return distance_squared <= radius_sum * radius_sum; } vec2 CollisionSystem::get_current_position(const vec2 & collider_offset, diff --git a/src/example/game.cpp b/src/example/game.cpp index af99097..be756bd 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -201,7 +201,7 @@ public: "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); game_object1.add_component(Rigidbody::Data{ .mass = 1, - .gravity_scale = 0.05, + .gravity_scale = 0, .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = {0, 0}, .constraints = {0, 0, 0}, -- cgit v1.2.3 From f4a182547e02bafaf996b7f504344c2e28d19254 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 6 Dec 2024 12:39:03 +0100 Subject: fixed float round issue --- src/crepe/system/CollisionSystem.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index bde217f..9da08cb 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -509,10 +509,10 @@ bool CollisionSystem::get_box_circle_collision(const BoxCollider & box1, // Calculate the distance squared between the circle's center and the closest point on the box float distance_x = final_position2.x - closest_x; float distance_y = final_position2.y - closest_y; - float distance_squared = distance_x * distance_x + distance_y * distance_y; + float distance_squared = std::round(distance_x * distance_x + distance_y * distance_y); // Compare distance squared with the square of the circle's radius - return distance_squared <= circle2.radius * circle2.radius; + return distance_squared < std::round(circle2.radius * circle2.radius); } bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1, @@ -527,13 +527,13 @@ bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1 float distance_x = final_position1.x - final_position2.x; float distance_y = final_position1.y - final_position2.y; - float distance_squared = distance_x * distance_x + distance_y * distance_y; + float distance_squared = std::round(distance_x * distance_x + distance_y * distance_y); // Calculate the sum of the radii float radius_sum = circle1.radius + circle2.radius; // Check if the distance between the centers is less than or equal to the sum of the radii - return distance_squared <= radius_sum * radius_sum; + return distance_squared < std::round(radius_sum * radius_sum); } vec2 CollisionSystem::get_current_position(const vec2 & collider_offset, @@ -554,3 +554,5 @@ vec2 CollisionSystem::get_current_position(const vec2 & collider_offset, // Final positions considering scaling and rotation return (transform.position + vec2(rotated_total_offset_x1, rotated_total_offset_y1)); } + + -- cgit v1.2.3 From 5350944a3967042e3eb1136859660addaa771593 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 6 Dec 2024 12:42:20 +0100 Subject: removed round --- src/crepe/system/CollisionSystem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 9da08cb..44ea7ee 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -509,10 +509,10 @@ bool CollisionSystem::get_box_circle_collision(const BoxCollider & box1, // Calculate the distance squared between the circle's center and the closest point on the box float distance_x = final_position2.x - closest_x; float distance_y = final_position2.y - closest_y; - float distance_squared = std::round(distance_x * distance_x + distance_y * distance_y); + float distance_squared = distance_x * distance_x + distance_y * distance_y; // Compare distance squared with the square of the circle's radius - return distance_squared < std::round(circle2.radius * circle2.radius); + return distance_squared < circle2.radius * circle2.radius; } bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1, @@ -527,13 +527,13 @@ bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1 float distance_x = final_position1.x - final_position2.x; float distance_y = final_position1.y - final_position2.y; - float distance_squared = std::round(distance_x * distance_x + distance_y * distance_y); + float distance_squared = distance_x * distance_x + distance_y * distance_y; // Calculate the sum of the radii float radius_sum = circle1.radius + circle2.radius; // Check if the distance between the centers is less than or equal to the sum of the radii - return distance_squared < std::round(radius_sum * radius_sum); + return distance_squared < radius_sum * radius_sum; } vec2 CollisionSystem::get_current_position(const vec2 & collider_offset, -- cgit v1.2.3