cube?

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

cube?

Post by ratman »

Has anyone imported the cube from LoG 1? if not can someone explain how to? thanks.
User avatar
Skuggasveinn
Posts: 561
Joined: Wed Sep 26, 2012 5:28 pm

Re: cube?

Post by Skuggasveinn »

Hi.

It's not just a question of importing it, the brain of the Cube is missing in LoG2, so that part has to be rewritten or faked in someway to get it to function they way the cube functions in LoG1.

Brains, or AI behavior has never been part of the released asset packs, so I have never seen the code behind a brain.
Importing the Cube and assigning it a different brain that is available does not really work also, you will get monster that tries to make 90 degree turns (missing animation) and behaves differently then what you would expect from the Cube, not to mention weird animation resets, moving forward one tile for a normal monster is an animation that goes from one tile to another and resets, moving forward one tile for the cube is one flip of the cube, it needs to make 4 flips until it is again back in the same position since the sides of the cube look different, so there is something special going on that tracks which side he is on.

hope that helps explain why this "simply" hasn't been done yet ;)

kind regards.
Skuggasveinn.
Link to all my LoG 2 assets on Nexus.
Link to all my LoG 1 assets on Nexus.
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: cube?

Post by ratman »

Okay, thanks. I don't think I'll be doing it anytime soon, since I cant even successfully import the animations for the cube :lol:
User avatar
Skuggasveinn
Posts: 561
Joined: Wed Sep 26, 2012 5:28 pm

Re: cube?

Post by Skuggasveinn »

Replying to this post got me thinking on how this could be faked, instead of importing the LoG1 Cube, what if one would recreate a new one, a cube that is the same on all sides to try to hide the animations skips.

I used the rat-swarm brain for behavior (that creates problems with projectiles that I haven't fixed) I then created single frame turning animations that I speed up to "hide" the 90 degrees turns, that worked out surprisingly well. Being a rat swarm brain the monster tries to move into the square of party and then "eat it", so the crush of the cube comes way way to late (the cube has landed over the party and then you die).

I was surprised that this wasn't nearly as bad as I thought at first, perhaps with more love and care and some scripting this could work out for a monster, but bringing the original cube that is different on all sides and has stopping, freezing, powering back up etc , I would not know where to begin with that.

The result is here.
https://youtu.be/WkBIytNvCGw

kind regards.
Skuggasveinn.
Link to all my LoG 2 assets on Nexus.
Link to all my LoG 1 assets on Nexus.
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: cube?

Post by minmay »

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.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Skuggasveinn
Posts: 561
Joined: Wed Sep 26, 2012 5:28 pm

Re: cube?

Post by Skuggasveinn »

I totally agree with you on the uniqueness of the Cube, that's way the idea of making a new Cube is more appealing to me, not that I'm actively working on any mod mind you :D , I just wanted to see how far I would go over the weekend.
The idea of multiple cubes is supported by the lore, one is buried on the island, and during the final cutscene you can see a full size cube next to one of the large bookshelf when the party enters the Nexus, clearly there are more then one.

I did notice in the original animations that It doesn't turn, and therefore the code is handling the rotation of the cube when its moving like you pointed out, even more interesting is when you directly convert the log1 animations into log2 and just throw the cube into the editor, it does rotate, meaning that something in the LoG2 code is also rotating it :o (I wonder what else is buried there ;) )

kind regards.
Skuggasveinn.
Link to all my LoG 2 assets on Nexus.
Link to all my LoG 1 assets on Nexus.
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: cube?

Post by ratman »

The result is here.
https://youtu.be/WkBIytNvCGw
:shock: That is amazing! I could not even begin to make something like that.(by the way, I would honestly much rather have that than the original cube)

@Minmay: Yes, I agree that the cube should be unique to grimrock 1. at first, my mod's whole storyline revolved around the cubes, but I decided to scrap that idea. (Though if anyone does manage to create their own, I would very much like it!)
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: cube?

Post by Zo Kath Ra »

ratman wrote: Wed Oct 14, 2020 1:50 am :shock: That is amazing!
Everything Skuggasveinn makes is amazing.
User avatar
Komag
Posts: 3654
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: cube?

Post by Komag »

I agree that the new cube video is very impressive!
Finished Dungeons - complete mods to play
Post Reply