diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-12-16 18:32:26 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-12-16 18:32:26 +0100 |
commit | b3f0e0da03a3cd4976a5a90d040cbe7fd7472987 (patch) | |
tree | 38ef4cee9d200269a5a0099df40d825dcb6525e8 /src | |
parent | 387bf02833c610f93326bf743db463eea8032a62 (diff) |
added dynamic bounce
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/system/CollisionSystem.cpp | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 4e84d8b..0cd6f5c 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -410,15 +410,69 @@ void CollisionSystem::dynamic_collision_handler(CollisionInfo & info){ switch (info.resolution_direction) { case Direction::BOTH: - info.this_rigidbody.data.linear_velocity = {0, 0}; + if (info.this_rigidbody.data.elastisity_coefficient > 0) { + info.this_rigidbody.data.linear_velocity + = -info.this_rigidbody.data.linear_velocity + * info.this_rigidbody.data.elastisity_coefficient; + } + else { + info.this_rigidbody.data.linear_velocity = {0, 0}; + } + + if (info.other_rigidbody.data.elastisity_coefficient > 0) { + info.other_rigidbody.data.linear_velocity + = -info.other_rigidbody.data.linear_velocity + * info.other_rigidbody.data.elastisity_coefficient; + } + else { + info.other_rigidbody.data.linear_velocity = {0, 0}; + } break; case Direction::Y_DIRECTION: - info.this_rigidbody.data.linear_velocity.y = 0; - info.this_transform.position.x -= info.resolution.x; + if (info.this_rigidbody.data.elastisity_coefficient > 0) { + info.this_rigidbody.data.linear_velocity.y + = -info.this_rigidbody.data.linear_velocity.y + * info.this_rigidbody.data.elastisity_coefficient; + } + // Stop movement + else { + info.this_rigidbody.data.linear_velocity.y = 0; + info.this_transform.position.x -= info.resolution.x; + } + + if (info.other_rigidbody.data.elastisity_coefficient > 0) { + info.other_rigidbody.data.linear_velocity.y + = -info.other_rigidbody.data.linear_velocity.y + * info.other_rigidbody.data.elastisity_coefficient; + } + // Stop movement + else { + info.other_rigidbody.data.linear_velocity.y = 0; + info.other_transform.position.x -= info.resolution.x; + } break; case Direction::X_DIRECTION: - info.this_rigidbody.data.linear_velocity.x = 0; - info.this_transform.position.y -= info.resolution.y; + if (info.this_rigidbody.data.elastisity_coefficient > 0) { + info.this_rigidbody.data.linear_velocity.x + = -info.this_rigidbody.data.linear_velocity.x + * info.this_rigidbody.data.elastisity_coefficient; + } + // Stop movement + else { + info.this_rigidbody.data.linear_velocity.x = 0; + info.this_transform.position.y -= info.resolution.y; + } + + if (info.other_rigidbody.data.elastisity_coefficient > 0) { + info.other_rigidbody.data.linear_velocity.x + = -info.other_rigidbody.data.linear_velocity.x + * info.other_rigidbody.data.elastisity_coefficient; + } + // Stop movement + else { + info.other_rigidbody.data.linear_velocity.x = 0; + info.other_transform.position.y -= info.resolution.y; + } break; case Direction::NONE: // Not possible |