I think you could implement the animations in a similar way to how Grimrock 1 does it. If you examine the cube's movement animation files from the Grimrock 1 asset pack, you'll find that it includes the movement of the cube's center and the animation of all the gears and buzzsaws and stuff inside, but doesn't rotate the whole cube; the rotation is done in the game code. And in Grimrock 2, we can control that rotation in our code too, with Component:setRotationAngles() on the ModelComponent!
You'll need to remove all the rotation keys from the root node when you port over the animations, using
my modification to the Blender exporter. Otherwise the animation will just overwrite your rotation every frame.
To know how the cube should be rotated on any particular frame, you need to know two things: where the center of the cube is, and what orientation it was in when it started moving.
There's a nice little hack that makes it easy to get the position of the center every frame: you can get the position of any node in a monster mesh by using MonsterComponent:shootProjectile([projectile name], [height], [attackPower], [node]) with the node's name as the fourth argument, then getting the world position of the returned projectile.
Code: Select all
local projectile = ogre_1.monster:shootProjectile("blob",0,0,"capsule")
local capsulePosition = projectile:getWorldPosition()
projectile:destroy()
As for the initial orientation, you can just keep track of that in your AI code (you'll be pretty much writing it from scratch anyway).
Or you could the same shootProjectile() trick at the beginning of the move for one of the nodes that
isn't at the center, and use that node's position relative to the center to determine which of the 24 possible orientations you're in. Inelegant and magic number-y, but it'd work.
I could go into how I think you could implement the knockback and crushing and assembling and disassembling the cube, but instead I'm going to poo-poo the whole idea a bit. The mechanical cube is the final and only boss of Legend of Grimrock and a major presence in the game's story. It's tied to the identity of the game in a way that cave ogres and wallsets and such are not. So as rich as this probably sounds coming from someone who ported a ton of Grimrock 1 stuff to Grimrock 2, I would urge you to rethink whether your mod
really benefits from having the cube in it. Most of the Grimrock 1 mods that used it sure didn't.
I made the conscious decision not to port it myself, and
not because it would have been too hard.