Screen shake onDamage possible?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Rook
Posts: 71
Joined: Thu Dec 06, 2012 5:48 pm
Location: Belfast, UK

Screen shake onDamage possible?

Post by Rook »

I'm just curious whether it is possible to add a minor screenshake upon taking damage or landing critical hits. I've been messing around with a few scripts, but I'm unable to get any solid results.
User avatar
Skuggasveinn
Posts: 562
Joined: Wed Sep 26, 2012 5:28 pm

Re: Screen shake onDamage possible?

Post by Skuggasveinn »

onDealDamage = function(self, champion, damage)
party:shakeCamera(0.5, 0.3)
party:playScreenEffect("damage_screen")

something along this line ?
Link to all my LoG 2 assets on Nexus.
Link to all my LoG 1 assets on Nexus.
User avatar
Rook
Posts: 71
Joined: Thu Dec 06, 2012 5:48 pm
Location: Belfast, UK

Re: Screen shake onDamage possible?

Post by Rook »

That basically the same to what I'm using. I'm just not sure what to add for (self, champion, damage). Especially damage.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Screen shake onDamage possible?

Post by Komag »

you don't need to add anything if you don't want to, they're just useful options
Finished Dungeons - complete mods to play
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Screen shake onDamage possible?

Post by JohnWordsworth »

I would consider doing something like the following in order to have the screen shake whenever the player takes damage (it's a tad harder for monsters, as you have to hook into every monster I believe).

You have to modify the default behaviour when the player takes damage by adding a party hook - these let you have custom lua functions, that you define, called when certain things happen to the party. Either add the following to init.lua or add it to a new file, party.lua and then add an import line to your init file to link in the new file.

Simple Shake Code (based on @Skugasveinn's script).

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",
  onDamage = function(champion, damage, damType)
    party:shakeCamera(0.5, 0.3);
    party:playScreenEffect("damage_screen");
    return true;
  end,
}
Slightly More Complex Shake Code (shakes more on more damage).

The function bit defines your custom logic - champion, damage and damType are parameters passed to your code from the game engine. Here we use those to shake the screen more if you take a higher proportion of damage.

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",
  onDamage = function(champion, damage, damType)
    local intensity = damage / champion:getStatMax("health");
    party:shakeCamera(intensity, 0.3);
    party:playScreenEffect("damage_screen");
    return true;
  end,
}
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Rook
Posts: 71
Joined: Thu Dec 06, 2012 5:48 pm
Location: Belfast, UK

Re: Screen shake onDamage possible?

Post by Rook »

That LUA works wonderfully. Much thanks, John. :)
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Screen shake onDamage possible?

Post by Komag »

Those are pretty straightforward and clear. I love messing with simple math in functions, it can get clever very fast, good stuff. :)

You can also leave off the "return true" line. It always returns true as a default, you only need to put something if you want it to "return false" or perhaps return some other value (rare/advanced).

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",
  onDamage = function(champion, damage, damType)
    party:shakeCamera(0.5, 0.3);
    party:playScreenEffect("damage_screen");
  end,
}

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",
  onDamage = function(champion, damage, damType)
    local intensity = damage / champion:getStatMax("health");
    party:shakeCamera(intensity, 0.3);
    party:playScreenEffect("damage_screen");
  end,
}
Finished Dungeons - complete mods to play
Post Reply