Trials and triumphs of whips and levers
For the past several months I've been working on improving the whip I prototyped last year and making it possible to use it to grab a lever. Here's what it looked like in June:
And here's what it looks like now:
I think this feels really good to use now. It didn't get to this point without a lot of issues on the way though.
A bit of background on how the whip is implemented in broad strokes. Using physics joints etc. quickly turned out infeasible when I did the prototype last fall. Instead, I’m keeping track of positions and velocities of “links” in arrays in my own scripts and doing very custom simulation with lots of tweaks and workarounds. Collisions with level geometry works by doing sphere-casts, one per whip link per frame, which is around 30.
There's special logic that makes the stick of the levers "sticky" and "unsticky" at specific times, which aids the behavior, but the way the whip curls around the stick (or fails to curl, sometimes) is still driven by the regular simulation apart from that. For all other surfaces, there's no special logic. It uses the sphere-cast based collision avoidance I mentioned above.
I should say there's a glaring issue in my collision approach which isn't shown in the video, which is that collision fails against moving surfaces, such as the moving platforms. I'm not quite sure if I want to solve that, because it's going to add tons of complexity to the code, while probably also degrade performance significantly. I've chosen to ignore this for now, since there's no lack of other things that need to be done that are more critical.
The lever has caused me all kinds of problems. Doing a lever that works properly, particularly for VR, is apparently a complicated problem. I made a video about my woes here:
I found out that levers could be made to avoid sliding out of their joints given two criteria are met:
First, the collider of the lever handle must not overlap with any other colliders in the world, including the collider the lever is attached to via the hinge joint. Normally colliders attached via hinges don't collide at all by default, but in our weird case here, it doesn't matter. Even if the two colliders are set to explicitly ignore each other via Physics.IgnoreCollision, the overlap still causes the issues regardless. So I ensured the handle collider doesn't overlap with any other colliders.
Secondly, the rigidbody must have its position set to locked.
Unfortunately, this leads to another problem. Sometimes the lever handle would get completely stuck, in which case no amount of forces would make it move one bit. After some experimentation, this seemed to happen if the handle is exerted to forces while the connected rigidbody (which is kinematic) simultaneously move. (Some levers in my game sometimes get moved around.) I worked around this by disabling the rigidbody position locking at strategic times and then reenabling it again. This seemed to fix the issue.
Polishing it up
After I had gotten most of the technical issues resolved, I set out to create proper 3d models for the whip and lever to replace the simple cylinder placeholders I had before.
And as the last step, I added the ability for the whip to be rolled up (which it now is by default). The whip is still fully simulated while rolled up, which is what gives the rolled up whip its nice juicy appearance. There's no animation or pre-canned movements involved in the whip at all.
The transition where the whip gets rolled up is done by pulling at specific segments of the whip towards a specific point on the handle. This happens to also be how the whip remains rolled up in general.
In the video I do a little upwards flick and then the whip rolls up. This is purely "role playing" though. The rolling up is actually triggered just by pressing a button on the controller. ;)
I won't have a new build available for a little while yet, but I'm very much looking forward to hear what you think once you can try it out yourselves!
(Note: The download button below doesn't work because this game has not been released. It's a bug in itch.io that the button shows up at all.)
Get Eye of the Temple
Leave a comment
Log in with itch.io to leave a comment.