From faa9adb84ad3f675587b52fba79cf44b7bdd2034 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 20 Nov 2024 20:50:48 +0100 Subject: added unit tests for dynamic box box collision --- src/crepe/system/CollisionSystem.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 2132b0d..b23e779 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -91,9 +91,11 @@ void CollisionSystem::collision_handler(CollidedInfoStor& data1,CollidedInfoStor move_back_direction = Direction::BOTH; } else if (move_back.x != 0) { move_back_direction = Direction::X_DIRECTION; + if(data1.rigidbody.data.linear_velocity.y != 0) move_back.y = data1.rigidbody.data.linear_velocity.y * (move_back.x/data1.rigidbody.data.linear_velocity.x); } else if (move_back.y != 0) { move_back_direction = Direction::Y_DIRECTION; + if(data1.rigidbody.data.linear_velocity.x != 0) move_back.x = data1.rigidbody.data.linear_velocity.x * (move_back.y/data1.rigidbody.data.linear_velocity.y); } @@ -341,13 +343,8 @@ bool CollisionSystem::check_circle_circle_collision(const CircleCollider& circle } Vector2 CollisionSystem::current_position(const Collider& collider, const Transform& transform, const Rigidbody& rigidbody) { - // Function to convert degrees to radians - auto degrees_to_radians = [](double degrees) { - return degrees * (M_PI / 180.0); - }; - // Get the rotation in radians - double radians1 = degrees_to_radians(transform.rotation); + double radians1 = transform.rotation * (M_PI / 180.0); // Calculate total offset with scale Vector2 total_offset = (rigidbody.data.offset + collider.offset) * transform.scale; -- cgit v1.2.3