Hi, Im new to Unity Development and wanted to know what the best method is to solve the problem below.
I am working in 2D and my player can fire a spear from a spear gun with a chain connected (preview included from java version below). This chain is collidable and increasing in height constantly (until it collides with something or the edge of the screen). My issue is the standard collider doesnt support directly changing its dimensions/shape once its already set and the solutions i do know of (and have implemented in java etc before) feel like hacks and usually involve messy direct handling of the box2D collider.
Solutions i am considering/aware of:
I solved this issue in java on an older version of the game about a year ago (but never finished the game and felt unity would be better now i have the time to do it again) so i have a few solutions i can think of. some i know work in java at least (where i have direct access to the collision engine) others are less ideal backup ideas.
Solution 1: each frame in the backend code where the spear is updated, destroy its collider and create a new one of the correct size *last time i did this in box2D java it required a workaround to get it to work correctly as box2D does not detect collisions on the first update after the collider is added and as the collider will always be renewed each update it never collides, im not sure this workaround is possible/needed in unity
Solution 2: implement my own physics throughout the game. This is allot of hassle to get looking good and feels wasteful when one already exists that i should be able to work with
Solution 3: somehow create two physics systems one hand made for the spear and use unity for the rest and somehow hook into the unity collision system to integrate the two. I think this is possible from what ive seen online but ive no idea where to start with it.
Solution 4: instead of working with a single collider and changing its shape, create a chain of multiple smaller colliders and spawn them as needed. the issues with this are balancing performance and accuracy, the smaller they are the more accurate collisions will be but the simulation will then need to handle far more colliders and when the object is destroyed suddenly clear out many, many colliders all at once which im uncertain is a good idea or the colliders are larger but this creates a greater error margin during gameplay. i should note there may be more than one spear on the screen at once, eventually the game should at least be capable of many many spears being shown with little to no performance impact.
So how in unity do you solve the problem of a collider changing dimensions each frame or update? Do i use one of the above solutions? if so advice might be needed on how to even do it (i know how to do allot of these solutions when im working low level with direct access to the underlying physics system but in unity im uncertain). if not does anyone have any other suggestions/advice on how to handle it?
Thanks in advance everyone