aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-11-17 19:04:33 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-11-17 19:04:33 +0100
commited04aa321fd390c45eff1fee03e73e6513c6b978 (patch)
tree767f1db1eda5a4dddecac21d704d214a3e26cf8d
parentb1c82f914f18457f9a30791b01896ea40832c2d3 (diff)
improved bounce
-rw-r--r--src/crepe/system/CollisionSystem.cpp7
-rw-r--r--src/example/collision.cpp8
2 files changed, 10 insertions, 5 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp
index 8377823..3c6f22e 100644
--- a/src/crepe/system/CollisionSystem.cpp
+++ b/src/crepe/system/CollisionSystem.cpp
@@ -153,7 +153,12 @@ void CollisionSystem::static_collision_handler(CollisionInfo& info){
std::cout << "INFO: x:" << info.first.transform.position.x << "y:" << info.first.transform.position.y << std::endl;
info.first.transform.position += info.move_back_value;
if(info.first.rigidbody.data.bounce) {
- info.first.rigidbody.data.linear_velocity = -info.first.rigidbody.data.linear_velocity * info.first.rigidbody.data.bouncie_factor;
+ if(info.move_back_value.x != 0) {
+ info.first.rigidbody.data.linear_velocity.x = -info.first.rigidbody.data.linear_velocity.x * info.first.rigidbody.data.bouncie_factor;
+ }
+ if(info.move_back_value.y != 0) {
+ info.first.rigidbody.data.linear_velocity.y = -info.first.rigidbody.data.linear_velocity.y * info.first.rigidbody.data.bouncie_factor;
+ }
}
else {
info.first.rigidbody.data.linear_velocity = {0,0};
diff --git a/src/example/collision.cpp b/src/example/collision.cpp
index b141d3d..2c476ca 100644
--- a/src/example/collision.cpp
+++ b/src/example/collision.cpp
@@ -63,10 +63,10 @@ int main(int argc, char * argv[]) {
.bounce = false,
.offset = {0,0}
});
- // World.add_component<BoxCollider>(Vector2{0, -740}, 1000, 1000); // Top
+ World.add_component<BoxCollider>(Vector2{0, 0-(screen_size_height/2+world_collider/2)}, world_collider, world_collider);; // Top
World.add_component<BoxCollider>(Vector2{0, screen_size_height/2+world_collider/2}, world_collider, world_collider); // Bottom
- // World.add_component<BoxCollider>(Vector2{-820, 0}, 1000, 1000); // Left
- // World.add_component<BoxCollider>(Vector2{820, 0}, 1000, 1000); // right
+ World.add_component<BoxCollider>(Vector2{0-(screen_size_width/2+world_collider/2), 0}, world_collider, world_collider); // Left
+ World.add_component<BoxCollider>(Vector2{screen_size_width/2+world_collider/2, 0}, world_collider, world_collider); // right
GameObject game_object1(1, "Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1);
@@ -74,7 +74,7 @@ int main(int argc, char * argv[]) {
.mass = 1,
.gravity_scale = 0.01,
.body_type = Rigidbody::BodyType::DYNAMIC,
- .linear_velocity = {0,0},
+ .linear_velocity = {1,0},
.constraints = {0, 0, 0},
.use_gravity = true,
.bounce = true,