Be the first to post for 'Finishing The Weapon System'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

Hi

I notice that currently if any character, including enemies and NPCs, enters a weapon pickup point the player’s weapon will change. I think the collider type needs to be checked in OnTrigger Enter.

Hello All

I have been looked at the courses Character Components and i didn’t really like the structure.

I guess my problem is that i come from a WoW type games, where damage is calculated based on a lot of differnt thing which Rick also touched on.
Is the current setup not a bit troublesome to extend?

I was looking to do something like this instead - Creating a gear class and a base stat class (possible setting base stats on Charecter).
Then having weapon and special abilities in two classes and a Damage class which handle the input from the 4 classes (base stats, Gear, Weapon and Specialabilities)
It should determine the correct animation (no weapon swing on fireball cast) - and calculate the damage from stats (crit, hit, str, int etc.), from gear (+x crit etc.), either a weapon hit damage (min and max) or spellcast (min and max damage range).
The damage class should also get level of target which compare to charecter could determine glancing blow, crushing blow, resistance etc.

The HealthSystem should also i my world read from basestats and gear so that health increases with lvl as my base stamina/health goes up and i get gear with stats.
It would leave HealthSystem more generic.

Do you guys see a better way?

I am doing a bit more like a single player arena brawler so i focus on combat and abilities and not so much on level design etc.

Hi Jacob, I just have a lot of faith in the ability for the code to be re-worked if and when required, regardless of the new requirements. I tend only to create architecture for requirements that I actually have in front of me right now.

1 Like

Hi again :slightly_smiling_face:

Working as a tester and the developers seem to dislike refactoring - maybe because the managers don’t see the good thing about it.
Being new i have allready retyped many thing many times :stuck_out_tongue:

I have an issue i could use the community to help me with tho.

If my player fires a fireball at an enemy and it collides and the enemy have a public takeDamage function that is called from the fireball with its damage - how do i incorporate my player in the damage calculates?

Think that my player is lvl 1 and fires a fireball with 10 damage at a enemy of lvl 10 - as the enemy is higher level i want the diferent between the player and the target to be taken into account.

But how do you send info to the fireball that it was launched by the player (and info about the player) - and then pass that info on to the enemy?

The fireball could call a getter on the enemy to get info from it and use it in its damagecalculation before calling the takeDamage funkction - but still lack the player on the fireball - and can’t think of a way to get that info…

@Jacob_Kjaergaard: If this is a single player game, then only the player will be firing the fireball projectile, right?

If that is the case, then in the fireball projectile script, create a reference to your player and get the player’s level (either make it public in the player class or make it a gettable field). Then use that level in your fireball damage calculation.

If this is multiplayer, or if you have enemies using the same fireball projectile script, then it gets a bit more complicated. You would probably have to have whoever fired the projectile pass its level along with the call to instantiate the projectile. (like if you call a function to spawn the fireball, then pass along the level of whoever fired it)

Hope that makes sense.

That might work… although I am pretty new to this myself and there might be a better way :slight_smile:

@OldRod It is single player but wanted to make it generic so enemy mages could use it.
Considered doing 2 version with either inheritance or interface to don’t duplicate code - but enemy mages could multiple levels…

But!!! You mentioned the instantiate function and read up on it. There is an overload where you can give the parent!!!
Thanks alot!

I moved the Dominant Hand script to the left hand for ranged weapons. Then it fits with the animation and all.

And also, as a right handed myself, I would want the bow to be in my left hand, controlling the arrow and string with my dominant hand for aiming purposes.

I would probably rename the script from DominantHand to WeaponHand or WieldingHand too.

I went ahead and changed the code to allow for a dominant hand script to be put on both hands and then for the weapons scriptabe object to call from an enum and instantiate the weapon into the correct hand.

First I duplicated the DominantHand script and renamed them to DominantHandLeft and DominantHandRight and placed them both on the players correct hands.

Then made the following changes in the scripts.

WeaponConfig.cs
added these two enums at the top

    public enum WeaponHands
    {
        OneHanded,
        TwoHanded
    }
    public enum DominantGripHand
    {
        RightHand,
        LeftHand
    }

added these two lines to your variables so they would show as drop down boxes in the inspector.

[SerializeField] WeaponHands weaponHands;
[SerializeField] DominantGripHand dominantGripHand;

then this at the bottom

public WeaponHands GetWeaponHand()
{
    return weaponHands;
}
public DominantGripHand GetDominantGrip()
{
    return dominantGripHand;
}

WeaponSystem.cs
rewrote the RequestDominantHand method as

private GameObject RequestDominantHand()
{
    var handed = weaponInUse.GetDominantGrip();
    if (handed == Weapon.DominantGripHand.RightHand)
    {
        var dominantHands = GetComponentsInChildren<DominantHandRight>();
        return dominantHands[0].gameObject;
    }
    if (handed == Weapon.DominantGripHand.LeftHand)
    {
        var dominantHands = GetComponentsInChildren<DominantHandLeft>();
        return dominantHands[0].gameObject;
    }
    return null;
}

pretty sure the PutWeaponInHand method is still the same as the video, but just to be safe:

public void PutWeaponInHand(WeaponConfig weaponToUse)
{
    currentWeaponConfig = weaponToUse;
    var weaponPrefab = weaponToUse.GetWeaponPrefab();
    GameObject dominantHand = RequestDominantHand();
    Destroy(weaponObject);
    weaponObject = Instantiate(weaponPrefab, dominantHand.transform);
    weaponObject.transform.localPosition = currentWeaponConfig.gripTransform.localPosition;
    weaponObject.transform.localRotation = currentWeaponConfig.gripTransform.localRotation;
    SetupWeaponAnimations();
}

I’m still really new to coding in C# and Unity, so it may not be the most efficient way to do it, but it works.

My weapons scriptable object in the inspector:

Untitled

1 Like

Privacy & Terms