Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Physics and Collision detection #3

Open
2 tasks done
Tracked by #1
BKSalman opened this issue Jun 24, 2022 · 3 comments
Open
2 tasks done
Tracked by #1

Physics and Collision detection #3

BKSalman opened this issue Jun 24, 2022 · 3 comments

Comments

@BKSalman
Copy link
Owner

BKSalman commented Jun 24, 2022

  • Physics
  • Collision detection
@BKSalman BKSalman mentioned this issue Jun 24, 2022
2 tasks
@BKSalman
Copy link
Owner Author

for the physics and collision detection I used "Rapier" a physics engine to handle it for me, I just have to tell the engine what entities I want to be effected by physics.

However I'm having a bit of an issue,
I'm making a top down 2d game and I can't seem to find the proper way of doing that, I made the player and the boxes dynamic rigid bodies so the player can push the boxes, and I hacked in a way to make that work, but for some reason when I make the boxes a fixed rigid body the collider doesn't stop the player from going inside the box when moving at a low velocity, I'm trying to search for a proper way to do it, but still didn't find anything useful.

I searched for how it works in the unity game engine, so I could maybe get a sense of how rigid bodies work, but I couldn't find a solution to my problem yet

@manel-graca
Copy link

How are you adding velocity to your player character?

@BKSalman
Copy link
Owner Author

BKSalman commented Jun 29, 2022

How are you adding velocity to your player character?

Hey, sorry for not replying!, I never got any comments on my issues before, so didn't expect to get one!

however, I got it working by adding the velocity by getting the delta of x and y then add it to a Vec2 and then making that equal the linear velocity for the player

    let x_axis = -(left as i8) + right as i8;
    let y_axis = -(down as i8) + up as i8;

    let mut move_delta = Vec2::new(x_axis as f32, y_axis as f32);
    if move_delta != Vec2::ZERO {
        move_delta /= move_delta.length();
    }

    // Update the velocity on the rigid_body_component,
    // the bevy_rapier plugin will update the Sprite transform.
    rb_vels.linvel = move_delta * player.velocity;

if you have a better solution in mind please don't hesitate to teach me!

also thanks for replying to my issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants