libgdx - 如何禁用碰撞
libgdx - How to disable collisions
所以我正在尝试制作一堵单向墙,这意味着我的演员只能将此物体扔到一侧(例如只能从底侧或上侧)。
我开始阅读本教程:one-way-walls
但是当我在检查演员的方向后尝试禁用碰撞时,它不起作用。
我想我的问题可以在这部分解决
Since we will be using BeginContact event which only occurs one time per collision, we can only use SetEnabled once to alter the behavior of the contact. The problem is the contact will revert to being enabled again after each step. We could make a note of which contacts we have disabled and then check the list of them every time in PreSolve, but that is kinda inefficient and more work than I can be bothered with today. Or any day actually :)
So we'll just quietly sneak into b2Contact.cpp and comment out the line at the beginning of the Update function which re-enables the contact. After you're done it should look like this: // Re-enable this contact.
//m_flags |= e_enabledFlag;
问题是我在 AndroidStudio 中使用 java 版本的 libgdx,我不知道如何查找和更改这段代码。
所以我需要一种方法来改变它,或者一个不同的解决方案来避免每个周期的这种碰撞状态"re-enabling"。
您可以在 preSolve
中解决此问题,并将状态(是否应启用接触)存储在灯具 userData
中。当然,您应该在 endContact
.
中恢复此标志
所以我正在尝试制作一堵单向墙,这意味着我的演员只能将此物体扔到一侧(例如只能从底侧或上侧)。 我开始阅读本教程:one-way-walls 但是当我在检查演员的方向后尝试禁用碰撞时,它不起作用。 我想我的问题可以在这部分解决
Since we will be using BeginContact event which only occurs one time per collision, we can only use SetEnabled once to alter the behavior of the contact. The problem is the contact will revert to being enabled again after each step. We could make a note of which contacts we have disabled and then check the list of them every time in PreSolve, but that is kinda inefficient and more work than I can be bothered with today. Or any day actually :) So we'll just quietly sneak into b2Contact.cpp and comment out the line at the beginning of the Update function which re-enables the contact. After you're done it should look like this: // Re-enable this contact. //m_flags |= e_enabledFlag;
问题是我在 AndroidStudio 中使用 java 版本的 libgdx,我不知道如何查找和更改这段代码。 所以我需要一种方法来改变它,或者一个不同的解决方案来避免每个周期的这种碰撞状态"re-enabling"。
您可以在 preSolve
中解决此问题,并将状态(是否应启用接触)存储在灯具 userData
中。当然,您应该在 endContact
.