使用 Box2D 减少反射角度

发布于 2024-11-27 11:46:34 字数 357 浏览 3 评论 0原文

各位,

我正在尝试对球以一定角度撞击墙壁的碰撞实现某种行为。我希望球保持全速,但我希望反射角度稍微减弱,以便它从来时的方向反弹得更少。

我尝试过摩擦、阻尼和恢复,但似乎没有什么对我的回弹角度产生影响。

有谁知道我可以让 box2d 做我想要它做的事情吗?

球反射角

image https://i.sstatic.net/lMwLN.png

感谢您的帮助! 肯

Folks,

I'm trying to implement a certain behavior to a collision where a ball hits a wall at an angle. I want the ball to maintain full velocity, but I would like for the angle of reflection to be somewhat muted, so that it bounces back less from the direction it came.

I've played around with friction, damping, and restitution, but nothing seems to make a difference in my return bounce angle.

Does anyone know of a way I can get box2d to do what I'm wanting it to do?

Ball angle of reflection

image
https://i.sstatic.net/lMwLN.png

Thanks for the help,!
ken

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

强者自强 2024-12-04 11:46:34

首先,您可以在您的世界中设置一个接触监听器,然后找出球与墙壁之间的确切碰撞。
其次,找出碰撞点。
最后,计算碰撞点与身体中心之间的角度。

比如

void contactListener::BeginContact(b2Contact *contact)
{
    //find out the collision between the ball and the wall.
    ....

    //find out the collision point
    b2WorldManifold worldManifold;
    contact->GetWorldManifold(&worldManifold);
    b2Vec2 collisionPoint = worldManifold.points[0];

    //calculate the angle between collision point and body center.
    b2Vec2 bodyCenter = body->GetWorldCenter;
    ...
}

我希望你能明白我的意思

Firstly,you can set a contactListener in your world, and then ,find out the exactly collision between the ball and the wall.
Secondly,find out the collision point.
Last, calculate the angle between collision point and body center.

such as

void contactListener::BeginContact(b2Contact *contact)
{
    //find out the collision between the ball and the wall.
    ....

    //find out the collision point
    b2WorldManifold worldManifold;
    contact->GetWorldManifold(&worldManifold);
    b2Vec2 collisionPoint = worldManifold.points[0];

    //calculate the angle between collision point and body center.
    b2Vec2 bodyCenter = body->GetWorldCenter;
    ...
}

I hope you can understand what I mean

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文