preventing fall damage

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!
nichg
Posts: 48
Joined: Thu Oct 11, 2012 12:38 pm

Re: preventing fall damage

Post by nichg »

minmay wrote:There's no horizontal gravity.
nichg wrote:This gave me an awesome idea. If we figure out how to mess with the party's gravity-based movement, can we create something where the party is actually flung upwards (e.g. maybe they have to bounce up into a teleporter at a higher elevation)?
Sure: just use setWorldPosition to place the party somewhere off the ground, then use "party.gravity:setFallingSpeed(velocity)" where velocity is the downward velocity you want the party to have. You can also use "party.gravity:disable()" to make them stop in midair and hover there, but it will be reactivated as soon as the party moves or turns with the keyboard (turning with mouselook, however, doesn't re-enable gravity). Note that the party can freely turn and move while "falling" upwards, but not downwards.

I was able to jump over the Forgotten River by typing this in the debug console:

Code: Select all

party:setWorldPosition(55.5,0.1,70.5,0) party.gravity:setFallingSpeed(-50)
though I took a lot of damage when I hit the ground.
Cool! I'm guessing that setWorldPosition just needs to place the party a sliver above ground-level so the engine thinks they're falling? Also, the move while falling upwards thing is kinda weird - certainly it could be used for puzzles, but it seems like it's going to be very counter-intuitive to the player, so maybe using onMove to intercept movement commands during a jump would be a good idea.

For horizontal motion, you could just have a timer that updates the party's in-plane position using setWorldPosition so long as 'isFalling' is true, and keep an eye out for when the party crosses a cell boundary. Alternately, maybe you can use Knockback? Might be more trouble than it's worth, though.
nichg
Posts: 48
Joined: Thu Oct 11, 2012 12:38 pm

Re: preventing fall damage

Post by nichg »

Okay, I tested and confirmed that you can do all sorts of crazy stuff with jumps/etc so long as you use a timer to control the party's motion. You do have to be very careful with details though - e.g. if you trigger the jump with a floor plate, wait for the party's movement animation to finish first, otherwise it ends up being very weird. Also, you have to calculate the horizontal and vertical velocities so that the party moves an integer number of tiles, or there's a bit of jerkiness on landing.

Anyhow, that aside, you can use this to solve the OP's problem of preventing fall damage. Here's what I did:

- Make an elevation change 7 tiles deep.
- Place a 'floor_trigger' at the elevation from which the party is expected to step off into the pit. This will trigger when the party steps off into thin air (whereas floor triggers at intermediate elevations on the way down will not fire). (Incidentally, this has made me appreciate how nice it'd be if we could get the equivalent generic trigger to whatever the game uses to figure out when you've entered a teleporter - e.g. a height-sensitive 'thing has entered a given cube' sensor.)
- Place a timer with its timer component set to disabled, disableSelf set to true, and an interval of 1.3 seconds
- Set the floor_trigger to enable the timer when it fires.
- Make a script which executes party.gravity:setFallingSpeed(0) when the timer fires

This basically lets the party fall, but 'catches' them just before they hit. Because we can't use a volumetric trigger, you have to be fairly precise with the timer settings. Alternately, you could use this to do fancy things like slow the party down continuously as they approach the ground, levitate the party at specific heights, etc.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: preventing fall damage

Post by minmay »

I would advise against doing what you are doing. It will break at low framerates. If you do not have a good understanding of how to implement variable-framerate physics (which is actually quite complicated to do properly, especially in a game where you don't know how most of it behaves!) I'd strongly recommend you not try to get all fancy with timers. You don't need them for pit falls or single party.gravity:setFallingSpeed() call jumps anyway: you can detect when the party lands by checking party:isFalling() and cancel damage/injuries with party.onDamage and party.onReceiveCondition.
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
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: preventing fall damage

Post by Dr.Disaster »

remilafo wrote:
GoldenShadowGS wrote:It worked for me. I have a fall from +1 to -7 elevation pit. the floor below has -1 elevation deep water. No damage at all when I splash into it.
I will try it again, perhaps water does buffer a bit of damage but +1 to -7 is only 8 cells. In my case i have the party transiting 7 to -7 9 times for a total of 126 cells. The acceleration is quick impressive, near the end of the transistion the party is clocking around 50 cells/s ...
I just tried the same with a fall thru 3 levels from +7 to -7 into a floor with a -1 water. Result: no damage.

Also i don't see your acceleration. Each fall in a level seems to starts with speed 0, like no momentum conserved with pits. The only time i see the build-up is when the party lands outside of water which tends to kill between 1 and 3 characters.
Post Reply