Extending the collision system #731
Replies: 5 comments
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022).
Posted: 2020-07-21 15:44:28
User: Sinus [] (age: 832 days 🙌; posts: 1)
Hello everyone,
i started to create a game some days ago. It is going to be a hobby project for the next two or three month. I saw the LITIENGINE, looked into it, liked it and decided to choose it for the game.
As a first intermediate step the game should be basicially a top-down car driving simulation. I implemented the player-controlled car as a subclass of Creature with a subclass of KeyboardEntityController for controlling the steering and speed. As the car can rotate freely, and not just 0°/90°/180°/270°, i used a single image for all directions and rotated that image by overriding "getAffineTransform()" in my subclass of EntityAnimationController:
@Override public AffineTransform getAffineTransform() { AffineTransform transform = new AffineTransform(super.getAffineTransform()); transform.rotate(Math.toRadians(-this.getEntity().getAngle()), this.getEntity().getWidth() / 2, this.getEntity().getHeight() / 2); return transform; }
This works fine and i can now drive around with the car, but i realised soon, that the implementation of collision will be more tricky.
As i understand it, at the moment the LITIENGINE supports non-rotated rectangular collision boxes, because the return type of ICollisionEntity's getCollisionBox() is Rectangle2D. This is not sufficient for my application so i plan to implement any changes to the collision system i require. Because the car is nearly rectangular, the minimum requirement is the rotation of the rectangular collision box with respect to the entity's angle. I would prefere an implementation with arbitrary collision shapes, similar to the hit box of CombatEntitiy.
Is my understanding of the engine's current capabilities correct and my (planned) implementation resonable?
Is an extention of the current collision system to support rotated rectangular collision boxes or even arbitrary collision shapes of interest for the LITIENGINE? In case it is, i would try to implement that in a hopefully useful way and commit my work to the eninge. Otherwise i will probably implement it in a way it just works for me.
How would an (useful) implementation look like? I believe i would have to replace "public Rectangle2D getCollisionBox()" with something like "public Shape getCollisionShape()" in the ICollisionEntity interface and make corresponding changes in the PhysicsEngine to support arbitrary shapes. This feels like a big change for a rare use-case?
I would like to hear your ideas,
Sinus
Beta Was this translation helpful? Give feedback.
All reactions