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. One of the needed things to make it behave whip-like is that in the spring code that maintains distance between adjacent links, one link should affect the other slightly more than the other affects the first. This is to simulate the fact that the whip gets thinner towards the end, which is critical for whip-like behavior.Collisions with level geometry works by doing sphere-casts, one per whip link per frame, which is around 30. The spherecasts are from the previous position of a segment to its new position, and if anything was hit, I move the new position to the intersection point, which should be in between the old and the original new position. That's the basics.
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?
1 comment:
To me it feels like we get something to play around with while traversing the space. I mean, even if we have nothing to whip at, we have something that reacts to the world in our hand, which I think is a good thing.
If I'm in a game and I have a tool or a weapon, I will try to use it on stuff if I have no better idea of what to do, or am unsure where to go. Maybe this will distract from the actual puzzle solving but at least it's one more option ;)
As for the whip itself, I think it looks super kinetic :o I cannot wait to interact with it :P And perhaps, uhm, break it ;) It sure gives the game an Indiana Jones feel, immediately, which is absolutely not a negative!
I love that VR has made physics in games so important, from my experience with screen games we don't usually get to see the physics work so close up and really scrutinize it. In VR it's the reverse, any small glitch is immediately apparent, at least if we interact with it directly.
Post a Comment