jakeb
New vMember
Posts: 2
|
Post by jakeb on Jun 8, 2024 20:05:23 GMT
Is left weapon for akimbo (dual wield) weapons? if so how do I go about setting that up?
EDIT - I managed to setup akimbo weapons by adding another muzzle transform and muzzleVFX to my gun prefab along with a second model. In the shooterManager script it will check whether a second muzzle transform exists and every other shot will use the second muzzle transform as the shoot origin. Now to figure out how to set up the hand IK so akimbo weapons have the left hand in the proper spot!
|
|
fawad
New vMember
Posts: 9
|
Post by fawad on Jul 4, 2024 11:25:23 GMT
Here is my modified Script for second weapon it took me too much time to get it done approx. 3 days
using System.Collections; using Invector.vMelee; using Invector.vShooter; using UnityEngine; namespace SpiderMan { public class SecondaryWeaponCreator : MonoBehaviour { [SerializeField] GameObject secondaryWeapon; [SerializeField] string handlerName; [SerializeField] bool isShooterWeapon; [SerializeField] vShooterManager shooterManager; [SerializeField] vMeleeManager meleeManager; GameObject createdWeapon; Transform weaponParent; void Start() { OnEnable(); } void OnDestroy() { OnDisable(); if (createdWeapon) Destroy(createdWeapon); } void OnEnable() { if (!weaponParent) { //Debug.Log("No Parent Found"); Animator animator = GetComponentInParent<Animator>(); if (animator) { var _otherSideHand = animator.GetBoneTransform(HumanBodyBones.LeftHand); var children = _otherSideHand.GetComponentsInChildren<Transform>(); for (int i = 0; i < children.Length; i++) if (children[i].gameObject.name.Equals(handlerName)) { weaponParent = children[i]; break; } } } if (weaponParent) { // Debug.Log("parent Exists"); CreateSecondaryWeapon(); } } private void CreateSecondaryWeapon() { if (createdWeapon) { // Debug.Log("Weapons Exists"); createdWeapon.SetActive(true); } else { //Debug.Log("Weapon Recreate"); createdWeapon = Instantiate(secondaryWeapon); createdWeapon.transform.parent = weaponParent; createdWeapon.transform.localPosition = Vector3.zero; createdWeapon.transform.localEulerAngles = Vector3.zero; } if (isShooterWeapon) { if (!shooterManager) { shooterManager = GetComponentInParent<vShooterManager>(); shooterManager.onUnequipWeapon.AddListener(UnEquipSecondaryWeapon); shooterManager.onStartReloadWeapon.AddListener(StartReloadingSecondaryWeapon); shooterManager.onStartShoot.AddListener(ShootSecondaryWeapon); } if (shooterManager) { shooterManager.SetLeftWeapon(createdWeapon); } } else { if (!meleeManager) meleeManager = GetComponentInParent<vMeleeManager>(); if (meleeManager) meleeManager.SetLeftWeapon(createdWeapon); } }
private void ShootSecondaryWeapon(vShooterWeapon weapon, Vector3 aimPosition, bool applyHipfirePrecision, bool scopeViewMode) { if (IsSameWeaponAsThis(weapon)) { var secWeapon = createdWeapon.GetComponent<vShooterWeapon>(); if (secWeapon && !secWeapon.CanDoShot) { return; } if (!secWeapon || !secWeapon.gameObject.activeInHierarchy) { return; }
if (secWeapon.dontUseReload) { shooterManager.LoadAllAmmo(secWeapon); } else if (secWeapon.autoReload && secWeapon.ammoCount <= 0 && shooterManager.WeaponHasUnloadedAmmo()) { shooterManager.ReloadWeapon(); return; }
var _aimPos = applyHipfirePrecision ? aimPosition + shooterManager.HipFirePrecision(aimPosition) : aimPosition; var sucessfulShot = false; secWeapon.Shoot(secWeapon.muzzle.position, _aimPos, transform, (bool sucessful) => { sucessfulShot = sucessful; });
shooterManager.UpdateAmmoDisplay(secWeapon.isLeftWeapon ? -1 : 1);
if (secWeapon.dontUseReload) { shooterManager.LoadAllAmmo(secWeapon); }
if (shooterManager.ExtraAmmo <= 0) { secWeapon.onFinishAmmo.Invoke(); } } }
private void StartReloadingSecondaryWeapon(vShooterWeapon thisWeapon) { if (IsSameWeaponAsThis(thisWeapon)) { var secWeapon = createdWeapon.GetComponent<vShooterWeapon>(); StartCoroutine(AddAmmoToWeapon(thisWeapon, secWeapon, secWeapon.reloadTime)); } }
private IEnumerator AddAmmoToWeapon(vShooterWeapon thisWeapon, vShooterWeapon secWeapon, float reloadTime) { if (secWeapon.ammoCount < secWeapon.clipSize && (secWeapon.isInfinityAmmo || shooterManager.AllAmmoInfinity || shooterManager.WeaponHasUnloadedAmmo()) && !secWeapon.dontUseReload && !shooterManager.cancelReload) { secWeapon.ReloadEffect(); yield return new WaitForSeconds(reloadTime); if (!shooterManager.cancelReload) { var needAmmo = secWeapon.reloadOneByOne ? 1 : secWeapon.clipSize - secWeapon.ammoCount;
if (!secWeapon.reloadOneByOne && (secWeapon.isInfinityAmmo || shooterManager.AllAmmoInfinity)) { secWeapon.AddAmmo(needAmmo); } else { if (!(secWeapon.isInfinityAmmo || shooterManager.AllAmmoInfinity) && shooterManager.WeaponAmmo(secWeapon).count < needAmmo) { needAmmo = shooterManager.WeaponAmmo(secWeapon).count; }
secWeapon.AddAmmo(needAmmo); shooterManager.WeaponAmmo(secWeapon).Use(needAmmo); } if (secWeapon.reloadOneByOne && secWeapon.ammoCount < secWeapon.clipSize && shooterManager.WeaponHasUnloadedAmmo()) { if (secWeapon.isInfinityAmmo == false && shooterManager.WeaponAmmo(secWeapon).count == 0) { secWeapon.FinishReloadEffect(); } else { if (!shooterManager.cancelReload) { StartCoroutine(AddAmmoToWeapon(thisWeapon, secWeapon, reloadTime)); } } } else { secWeapon.FinishReloadEffect(); } } shooterManager.UpdateTotalAmmo(); } }
private void UnEquipSecondaryWeapon(vShooterWeapon arg0, bool arg1) { if (IsSameWeaponAsThis(arg0)) { shooterManager.SetLeftWeapon(null); } }
private bool IsSameWeaponAsThis(vShooterWeapon arg0) { if (TryGetComponent<vShooterWeapon>(out var weapon)) { if (arg0 == weapon) { return true; } } return false; }
void OnDisable() { if (createdWeapon) { createdWeapon.SetActive(false); if (meleeManager) meleeManager.leftWeapon = null; if (shooterManager) shooterManager.SetLeftWeapon(null); } } } }
|
|