I have a 3D scene with 3D model instances; and I want to do collision detection. I'm currently following this tutorial (http://blog.xoppa.com/using-the-libgdx-3d-physics-bullet-wrapper-part1/). However, what I want is a bit more complicated.
There's a character (a knight.g3db model that's part of the sample code from Libgdx basic 3d model class), and it can attack with a sword. I also have another model instance that I want to "attack" with the sword.
Checking if the two objects for collision isn't the problem since that can easily be detected from the Bullet library. What I would like is possibly the following, but I'm not sure how to implement:
- Have the sword as the collision object, or
- Implement checking if only the front part of the "box" of the knight is colliding with the other object, or
- Create a separate invisible virtual box in front of the knight character and use that as basis if there's a collision.
Are there any references that you know that can do this (if the above proposed solutions are even possible)? Or if there's a better solution, please let me know.
What I'm trying to avoid: knight attacking while the other object is behind and still getting hit.
Thanks in advance.
These are what I used to check if the enemy object is within the 'field of view' of the hero (Working code):
Thanks to @Menno Gouw for the idea on getting the angle from Vector3.
And the code below is how I used these helper methods:
Hope this helps you if you're encountering the same issue. Feel free to make changes if there are improvements or issues with this.
If you just want to avoid enemies in your back being hit you could check if you are facing them. I'll take it you have a direction Vector for movement, check the difference in rotation of that Vector vs the vector calculated based on your position and the enemy.
Something like this (Disclaimer: out of my head, not sure if this work and just to give you an idea):
This might not be the ideal solution but it sure is a cheap solution and it might work very well.