Head Swaying from damage

Discuss coding questions, pull requests, and implementation details.
User avatar
MeteoricDragon
Posts: 141
Joined: Mon Feb 12, 2018 8:23 pm

Head Swaying from damage

Post by MeteoricDragon »

The classic Daggerfall had a built-in head swaying back-and-forth motion that happened whenever hit with an attack to simulate you trying to regain your composure from an attack and I believe it adds to the immersion of the game just like a subtle head bobbing does.

I'd like to create a script called HeadSwayer : MonoBehaviour and I think I could do the implementation of the head swaying with what I've learned from doing the head-bobbing feature. I've been doing searches in the code for "HealthDamage" and "DamageTaken" but nothing relevant has appeared. If I could call a function or property that returns the amount of damage the player suffered since the last frame, I could calculate the severity of Head Sway based on the percentage of player's total health lost. Also, I think I could script the player falling to the ground.

Does anyone know of said property or function? If i knew the name I would just type it in. but right now I'm limited to guessing the property's name. ;)

EDIT: Looks like it doesn't exist. I'll add a property in EnemyAttack unless I hear otherwise.

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Head Swaying from damage

Post by Interkarma »

This reeling effect can happen in classic Daggerfall whenever player takes a substantial amount of damage (not sure of actual %). I'm pretty sure I've seen it happen when surviving big falls as well, not just from enemy damage. I'd have to check, but I think it also freezes the ability of the player to move for a moment.

Rather than add a property to EnemyAttack, a better solution might be to sample the state of the player's health and fire head swaying after a significant loss. For example, do something like this in your HeadSwayer component.

Code: Select all

// Fields
int previousPlayerHealth;

// Update()
const float triggerSwayOnHealthPercentLost = 0.15f;
int maxPlayerHealth = GameManager.Instance.PlayerEntity.MaxHealth;
int currentPlayerHealth = GameManager.Instance.PlayerEntity.CurrentHealth;
if (currentPlayerHealth < previousPlayerHealth - maxPlayerHealth * triggerSwayOnHealthPercentLost)
{
    // Perform head-sway methods - pass in total % loss if using this to inform severity of sway
}
previousPlayerHealth = currentPlayerHealth;
That would allow effect to fire after other big hits as well, not just from enemy damage. I recommend spending some time with classic to observe its handling of this and try to implement as close to classic as possible. It would also be nice to have another toggle setting for this so users can disable if preferred (e.g. if it makes them feel motion-related discomfort).
MeteoricDragon wrote: Sun Apr 01, 2018 6:17 pm Also, I think I could script the player falling to the ground.
Can you elaborate on falling to the ground in this context? The only time I'm familiar with player falling to ground is after death, which is already in place.

User avatar
MeteoricDragon
Posts: 141
Joined: Mon Feb 12, 2018 8:23 pm

Re: Head Swaying from damage

Post by MeteoricDragon »

Well, I remember Zombies hitting my player for the first time and I couldn't aim straight at them.

You are correct about all sources of damage. However, i've just confirmed that it isn't based on a percentage lost of the user's health, i just jumped off the top of the stairs in the main room with throne lever at privateer's hold and lost almost all my health from mostly full and it just shook a light-moderate amount.

EDIT: if you ask me, I think that in classic, each enemy has a hit force that gets applied to the player which makes his view sway. Try getting hit by a zombie when you're lower level and you'll see right away that it's a lot worse than getting hit by even another human class enemy.

EDIT2: When i tested the game this morning, I didn't fall to death when an enemy killed my character. I thought it hadn't been implemented yet.

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Head Swaying from damage

Post by Interkarma »

MeteoricDragon wrote: Sun Apr 01, 2018 10:36 pm EDIT: if you ask me, I think that in classic, each enemy has a hit force that gets applied to the player which makes his view sway. Try getting hit by a zombie when you're lower level and you'll see right away that it's a lot worse than getting hit by even another human class enemy.
Interesting idea. This might be a good question for Allofich/R.D. Does anyone else have any observations around this?
MeteoricDragon wrote: Sun Apr 01, 2018 10:36 pm EDIT2: When i tested the game this morning, I didn't fall to death when an enemy killed my character. I thought it hadn't been implemented yet.
You've just found a bug introduced by the headbobber. :) When player dies with headbobber enabled, they will stand straight back up again after the drop animation plays. It should be easy fix for you though, good work catching it.

User avatar
MeteoricDragon
Posts: 141
Joined: Mon Feb 12, 2018 8:23 pm

Re: Head Swaying from damage

Post by MeteoricDragon »

Here's a preview of the progress of the headswayer class. Right now it's triggered by a minimum percentage loss in health, and right now it will shake once when first loading a game. the sway is the same anytime health is lost. It's not the same as classic Daggerfall though.

I'd like to hear how to better implement the severity of the sway depending on creatures that attack? I can only test so well in Daggerfall classic because I don't have the characters to test out how much difference in recoil they make the player feel when hitting him/her.


User avatar
MeteoricDragon
Posts: 141
Joined: Mon Feb 12, 2018 8:23 pm

Re: Head Swaying from damage

Post by MeteoricDragon »

Here's a thought. How can I get the Creature's level who is attacking the player, and the player's level in code?
Edit: or compare the strength of the two?

If I can scale the severity of the recoil with the difference in level between the player and enemy, that may be a good scalar.

User avatar
Arl
Posts: 202
Joined: Sun Mar 22, 2015 10:57 am

Re: Head Swaying from damage

Post by Arl »

I just tested the new build, head bobbing is great and now the Esc menu has more functionality, keep up the good work MeteoricDragon!
My Deviantart page, I have some Daggerfall stuff in there.

User avatar
King of Worms
Posts: 4752
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: Head Swaying from damage

Post by King of Worms »

Dmg sway looks really good, cant test the headbob as im not at my pc for next 2 weeks. Great job!

R.D.
Posts: 379
Joined: Fri Oct 07, 2016 10:41 am

Re: Head Swaying from damage

Post by R.D. »

EDIT: if you ask me, I think that in classic, each enemy has a hit force that gets applied to the player which makes his view sway. Try getting hit by a zombie when you're lower level and you'll see right away that it's a lot worse than getting hit by even another human class enemy.
Interesting idea. This might be a good question for Allofich/R.D. Does anyone else have any observations around this?
From what I've found of this code, it is only based on the damage amount. There is no "per enemy type" component.

Al-Khwarizmi
Posts: 177
Joined: Sun Mar 22, 2015 9:52 am

Re: Head Swaying from damage

Post by Al-Khwarizmi »

Aren't there damage types in Daggerfall? (e.g. the thing that makes blunt weapons more damaging to skeletons). Couldn't that have an influence? Or does reverse engineering indicate that it's definitely just damage amount?

Post Reply