Quick bug fixes

fixed pickup weapon
fixed drop weapon
changed switch weapon
This commit is contained in:
Noah4ever
2021-12-14 20:18:18 +01:00
parent 0fc8c6e08c
commit bdf043d299
4 changed files with 35 additions and 28 deletions

View File

@@ -180,7 +180,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 47740257}
m_LocalRotation: {x: -0, y: 0.76803535, z: -0, w: 0.64040744}
m_LocalPosition: {x: 11.263, y: 2.265, z: -0.464}
m_LocalPosition: {x: 11.263, y: 2.265, z: -0.462}
m_LocalScale: {x: 0.19765502, y: 0.19765502, z: 0.19765502}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -752,7 +752,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: grenadeRadius
value: 5
value: 6
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: showExplosion
@@ -2549,7 +2549,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: grenadeRadius
value: 5
value: 6
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: showExplosion
@@ -2557,7 +2557,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: explosionForce
value: 850
value: 1000
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: explodeParticle
@@ -5682,7 +5682,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: grenadeRadius
value: 5
value: 6
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: showExplosion
@@ -5690,7 +5690,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: explosionForce
value: 900
value: 1000
objectReference: {fileID: 0}
- target: {fileID: 9082234699677627348, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: explodeParticle
@@ -6153,7 +6153,7 @@ Rigidbody:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2019358521}
serializedVersion: 2
m_Mass: 1
m_Mass: 1.3
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1

View File

@@ -133,13 +133,13 @@ public class ProcedualAnimationController : NetworkBehaviour
// Getting right camera shake curve
if(distance < nearDistance) {
cameraShakeCurve = nearCameraShakeCurve; // high camera shake
Debug.Log("NEAR EXPLOSION: " + distance);
//Debug.Log("NEAR EXPLOSION: " + distance);
} else if(distance < mediumDistance){
cameraShakeCurve = mediumCameraShakeCurve; // medium camera shake
Debug.Log("MEDIUM EXPLOSION: " + distance);
//Debug.Log("MEDIUM EXPLOSION: " + distance);
} else if(distance < farDistance) {
cameraShakeCurve = farCameraShakeCurve; // little camera shake
Debug.Log("FAR EXPLOSION: " + distance);
//Debug.Log("FAR EXPLOSION: " + distance);
} else { // If distance is even further than far then no camera shake
cameraShake = false;
}

View File

@@ -77,7 +77,8 @@ public class Shoot : NetworkBehaviour
Debug.Log("ThrowGrenade!");
// Throws grenade with dropForce
weapon.HasBeenThrown = true;
weaponManager.dropWeapon(weapon.DropForce);
// 3 -> Grenade index
weaponManager.dropWeapon(weapon.DropForce, 3);
weaponManager.switchWeapon(1);
}

View File

@@ -28,21 +28,18 @@ public class WeaponManager : NetworkBehaviour
lastWeaponIndex = currentWeaponIndex;
activeWeapons[currentWeaponIndex].SetActive(false);
switchWeapon(-1);
activeWeapons[currentWeaponIndex].SetActive(true);
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0f) { // Scroll down
lastWeaponIndex = currentWeaponIndex;
activeWeapons[currentWeaponIndex].SetActive(false);
switchWeapon(1);
activeWeapons[currentWeaponIndex].SetActive(true);
}
if (Input.GetButtonDown("Interact")) { // e
PickupWeapon();
}else if (Input.GetButtonDown("Drop")) { // q Droping weapon
if (activeWeapons[currentWeaponIndex] != null) {
dropWeapon(activeWeapons[currentWeaponIndex].GetComponent<Weapon>().DropForce); // Throws weapon away
dropWeapon(activeWeapons[currentWeaponIndex].GetComponent<Weapon>().DropForce, currentWeaponIndex); // Throws weapon away
switchWeapon(1);
activeWeapons[currentWeaponIndex].SetActive(true);
}
}
}
@@ -57,8 +54,10 @@ public class WeaponManager : NetworkBehaviour
Weapon weaponData = activeWeapons[currentWeaponIndex].GetComponent<Weapon>();
procedualAnimationController.GunRightHandREF = weaponData.GunRightREF;
procedualAnimationController.GunLeftHandREF = weaponData.GunLeftREF;
switchAnimation(weaponData.WeaponKind.ToString()); // play weapon switch animation
// Play weapon switch animation
switchAnimation(weaponData.WeaponKind.ToString());
activeWeapons[currentWeaponIndex].SetActive(true);
return false;
}
private void switchAnimation(string weaponType) {
@@ -99,16 +98,21 @@ public class WeaponManager : NetworkBehaviour
private void PickupWeapon() {
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit))
{
if (hit.transform.tag == "Weapon") // If Object is a weapon and the weapon is not in the current active weapons
{
foreach (GameObject obj in activeWeapons) { // Disable all weapons
// If Object is a weapon and the weapon is not in the current active weapons
if (hit.transform.tag == "Weapon")
{
// Disable all weapons
foreach (GameObject obj in activeWeapons) {
if (obj != null) { obj.SetActive(false); }
}
hit.transform.parent = gunHolster.transform; // Parent weapon to gunHolster
// Parent weapon to gunHolster
hit.transform.parent = gunHolster.transform;
hit.rigidbody.isKinematic = true;
hit.rigidbody.useGravity = false;
SetAllColliderStatus(hit.transform.gameObject, false); // Disable all Collider
switch (hit.transform.GetComponent<Weapon>().WeaponKind.ToString()) { // Adding weapon to inventory slot
// Disable all Collider
SetAllColliderStatus(hit.transform.gameObject, false);
// Adding weapon to inventory slot
switch (hit.transform.GetComponent<Weapon>().WeaponKind.ToString()) {
case "Rifle": putWeaponInArray(0, hit); break;
case "Pistole": putWeaponInArray(1, hit); break;
case "Knife": putWeaponInArray(2, hit); break;
@@ -121,7 +125,8 @@ public class WeaponManager : NetworkBehaviour
private bool putWeaponInArray(int index, RaycastHit hit) {
if (activeWeapons[index] != null) {
dropWeapon(activeWeapons[currentWeaponIndex].GetComponent<Weapon>().DropForce); // Throws weapon away
// Throws weapon away
dropWeapon(activeWeapons[index].GetComponent<Weapon>().DropForce, index);
}
activeWeapons[index] = hit.transform.gameObject;
activeWeapons[index].SetActive(true);
@@ -135,17 +140,18 @@ public class WeaponManager : NetworkBehaviour
return true;
}
public bool dropWeapon(float dropForce) {
if(currentWeaponIndex != 2) {
GameObject currentWeapon = activeWeapons[currentWeaponIndex];
public bool dropWeapon(float dropForce, int index) {
if(index != 2) {
GameObject currentWeapon = activeWeapons[index];
currentWeapon.SetActive(true);
Rigidbody rigid = currentWeapon.GetComponent<Rigidbody>();
rigid.useGravity = true;
rigid.isKinematic = false;
rigid.velocity = cam.transform.forward * dropForce + cam.transform.up * 2;
SetAllColliderStatus(currentWeapon, true); // Activate all Collider
// Activate all Collider
SetAllColliderStatus(currentWeapon, true);
currentWeapon.gameObject.transform.SetParent(null);
activeWeapons[currentWeaponIndex] = null;
activeWeapons[index] = null;
return true;
}
else {