Rune Skovbo Johansen
Creative Programmer & Designer


July update: Trials and triumphs of whips and levers

Here's the latest updates on the development of my Vive VR game Eye of the Temple.

For the past several months I've been working on improving the whip I prototyped last year. In the last post, I showed how it could grab levers, but there were a lot of issues and the whip and lever didn't exactly look pretty. Now see what it looks like now:

This feels really good to use now. It didn't get to this point without a lot of issues on the way though.

The whip

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

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 three criteria are met:

First, the collider of the lever handle must not overlap with any other colliders in the world. The tricky thing here is that it's not easy to see that overlapping colliders might affect the handle, since the handle is firmly locked in place. But they do affect it in very non-obvious ways. So I ensured the handle collider doesn't overlap with any other colliders.

Secondly, the rigidbody must have its position set to locked.

Thirdly, the center of mass of the rigidbody must be overwritten in script to be set to the pivot that the handle should rotate around. 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. ;)

If you've been following the development of Eye of the Temple, does the whip related gameplay change how you view the game? What do you think it adds to it?
Read More »