fixed strafing, added shooting effects, created a new testing level, enlarged enemies, updated bullet firing system

This commit is contained in:
2023-05-29 00:16:05 -04:00
parent 461a297e12
commit 77ba05e7dc
159 changed files with 126161 additions and 502 deletions

View File

@ -1,10 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using Unity.Burst.CompilerServices;
using UnityEngine;
using UnityEngine.VFX;
public class PistolComponent : MonoBehaviour
{
public enum AimMode {GUN,MODIFIED,CAMERA};
public AimMode aimMode = AimMode.CAMERA;
[SerializeField]
private Light targetingLight;
@ -27,9 +31,17 @@ public class PistolComponent : MonoBehaviour
private float maxProjectileDuration = 5f;
[SerializeField]
private float maxTargetObjDistance = 15f;
[SerializeField]
private VisualEffect shootEffect;
[SerializeField]
private Light shootLight;
[SerializeField]
private float shootLightDuration = 0.1f;
private float timeSinceLightDuration = 0f;
private bool hasCloseTarget = false;
[SerializeField]
private LayerMask ignoreLayers;
//private Dictionary<int,float> projectiles = new Dictionary<int, float>();
@ -42,7 +54,7 @@ public class PistolComponent : MonoBehaviour
// Update is called once per frame
void Update()
{
timeSinceLightDuration += Time.deltaTime;
}
private float CalculateDrop(Vector3 origin,Vector3 destination,Vector3 force)
{
@ -61,12 +73,19 @@ public class PistolComponent : MonoBehaviour
}
private void FixedUpdate()
{
if (this.IsEnabled)
if (shootLight.gameObject.activeSelf&&timeSinceLightDuration>shootLightDuration)
{
shootLight.gameObject.SetActive(false);
}
if (aimMode==AimMode.CAMERA)
{
targetObject.gameObject.transform.position = PlayerAim.active.targetPosition;
}
if (this.IsEnabled&&aimMode!=AimMode.CAMERA)
{
Ray ray = new Ray(transform.position, transform.up);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 50))
if (Physics.Raycast(ray, out hit, 50,ignoreLayers))
{
float hitDist = Vector3.Distance(hit.point, transform.position);
@ -101,15 +120,17 @@ public class PistolComponent : MonoBehaviour
}
public void Fire()
{
Fire(!hasCloseTarget);
}
public void Fire(bool offsetWithTargetBall)
{
shootLightDuration = 0;
shootLight.gameObject.SetActive(true);
GameObject projectile = Instantiate(projectilePrefab, this.bulletSpawnPoint);
projectile.transform.localPosition = Vector3.zero;
projectile.transform.localEulerAngles = Vector3.zero;
@ -123,22 +144,32 @@ public class PistolComponent : MonoBehaviour
*/
Vector3 launchVector = pRigid.transform.up * this.firePower;
if(offsetWithTargetBall)
if(offsetWithTargetBall||aimMode==AimMode.MODIFIED)
{
Vector3 ballCamVector = targetObject.transform.position - this.GetComponentInParent<PlayerMovementController>().cam.transform.position;
Ray r = new Ray();
r.origin = targetObject.transform.position;
r.direction = ballCamVector.normalized;
RaycastHit hit;
if (Physics.Raycast(r,out hit))
if (Physics.Raycast(r,out hit,ignoreLayers))
{
launchVector = (hit.point - pRigid.transform.position).normalized;
launchVector *= this.firePower;
}
}
else if(aimMode==AimMode.CAMERA)
{
Vector3 target = PlayerAim.active.targetPosition;
Vector3 lv = target - pRigid.transform.position;
launchVector = lv.normalized;
launchVector*= this.firePower;
}
pRigid.AddForce(launchVector, ForceMode.Impulse);
projectile.transform.parent = null;
shootEffect.Play();
@ -160,6 +191,7 @@ public class PistolComponent : MonoBehaviour
Destroy(targetObject);
}
}
public void LightToggle() {
this.targetingLight.gameObject.SetActive(!this.targetingLight.gameObject.activeSelf);