Steam lobby implemented

This commit is contained in:
Madhav Kapa
2023-06-01 08:03:48 -07:00
parent c7647c8097
commit 49efee80e2
95 changed files with 10258 additions and 6167 deletions

View File

@ -1,42 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletComponent : MonoBehaviour
{
[SerializeField]
private float duration = 5f;
private float existed = 0f;
[SerializeField]
private string type = "flare";
[SerializeField] private float duration = 5f;
[SerializeField] private string type = "flare";
[SerializeField] private float damageRange = 20f;
[SerializeField] private float damageMagnitude = 1f;
private float existed;
private FlareRegister register;
[SerializeField]
private float damageRange = 20f;
[SerializeField]
private float damageMagnitude = 1f;
public float DamageMagnitude { get { return this.damageMagnitude; } }
public float DamageRange { get { return damageRange; } }
public float DamageMagnitude => damageMagnitude;
public float DamageRange => damageRange;
// Start is called before the first frame update
void Start()
private void Start()
{
register = FlareRegister.instance;
register.bullets.Add(this);
}
// Update is called once per frame
void Update()
private void Update()
{
}
private void FixedUpdate()
{
if(existed >= duration)
if (existed >= duration)
{
register.bullets.Remove(this);
Destroy(this.gameObject);
Destroy(gameObject);
}
existed += Time.fixedDeltaTime;
}
}
}

View File

@ -1,28 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PistolAnimationAimAssist : MonoBehaviour
{
public Transform leftShoulder;
public Transform rightShoulder;
[SerializeField]
private bool isEnabled = false;
Vector3 lTarget;
Vector3 rTarget;
[SerializeField] private bool isEnabled;
private Animator anim;
private Vector3 lTarget;
private Vector3 rTarget;
// Start is called before the first frame update
void Start()
private void Start()
{
lTarget = new Vector3(72.9f, 122.2f, -129.9f);
rTarget = new Vector3(82f, 11f, -88f);
anim =GetComponent<Animator>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
private void Update()
{
if (isEnabled)
{
@ -33,12 +32,14 @@ public class PistolAnimationAimAssist : MonoBehaviour
anim.StartPlayback();
}
}
public void Enable()
{
isEnabled = true;
}
public void Disable()
{
isEnabled = false;
}
}
}

View File

@ -1,127 +1,124 @@
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 enum AimMode {GUN,MODIFIED,CAMERA};
public AimMode aimMode = AimMode.CAMERA;
[SerializeField]
private Light targetingLight;
[SerializeField] private Light targetingLight;
[SerializeField] private GameObject targetObjectPrefab;
[SerializeField] public GameObject projectilePrefab;
[SerializeField] public string projectileName;
[SerializeField] private Transform bulletSpawnPoint;
[SerializeField] private float firePower = 20f;
[SerializeField] private float maxProjectileDuration = 5f;
[SerializeField] private float maxTargetObjDistance = 15f;
[SerializeField] private VisualEffect shootEffect;
[SerializeField] private Light shootLight;
[SerializeField] private float shootLightDuration = 0.1f;
[SerializeField] private LayerMask ignoreLayers;
private bool hasCloseTarget;
private bool IsEnabled = false;
GameObject targetObject;
[SerializeField]
GameObject targetObjectPrefab;
[SerializeField]
public GameObject projectilePrefab;
[SerializeField]
public string projectileName;
[SerializeField]
private Transform bulletSpawnPoint;
[SerializeField]
private float firePower = 20f;
[SerializeField]
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 IsEnabled;
private bool hasCloseTarget = false;
[SerializeField]
private LayerMask ignoreLayers;
private GameObject targetObject;
private float timeSinceLightDuration;
public bool IsLightOn => targetingLight.gameObject.activeSelf;
//private Dictionary<int,float> projectiles = new Dictionary<int, float>();
// Start is called before the first frame update
void Start()
private void Start()
{
}
// Update is called once per frame
void Update()
private void Update()
{
timeSinceLightDuration += Time.deltaTime;
}
private float CalculateDrop(Vector3 origin,Vector3 destination,Vector3 force)
{
// Calculate the initial velocity required to reach the destination.
Vector3 displacement = destination - origin;
float time = Mathf.Sqrt(2f * displacement.magnitude / Physics.gravity.magnitude);
Vector3 velocity = (displacement - 0.5f * Physics.gravity * time * time) / time + force;
// Calculate the height the object will reach during its flight.
float maxHeight = origin.y + velocity.y * time - 0.5f * Physics.gravity.y * time * time;
// Calculate the distance the object will drop during its flight.
float dropDistance = maxHeight - destination.y;
return dropDistance;
}
private void FixedUpdate()
{
if (shootLight.gameObject.activeSelf&&timeSinceLightDuration>shootLightDuration)
{
if (shootLight.gameObject.activeSelf && timeSinceLightDuration > shootLightDuration)
shootLight.gameObject.SetActive(false);
}
if (aimMode==AimMode.CAMERA)
if (aimMode == AimMode.CAMERA) targetObject.gameObject.transform.position = PlayerAim.active.targetPosition;
if (IsEnabled && aimMode != AimMode.CAMERA)
{
targetObject.gameObject.transform.position = PlayerAim.active.targetPosition;
}
if (this.IsEnabled&&aimMode!=AimMode.CAMERA)
{
Ray ray = new Ray(transform.position, transform.up);
var ray = new Ray(transform.position, transform.up);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 50,ignoreLayers))
if (Physics.Raycast(ray, out hit, 50, ignoreLayers))
{
float hitDist = Vector3.Distance(hit.point, transform.position);
var hitDist = Vector3.Distance(hit.point, transform.position);
if (hitDist < maxTargetObjDistance)
{
targetObject.gameObject.transform.position = hit.point;
targetObject.gameObject.GetComponent<MeshRenderer>().materials[0].SetColor("_EmissiveColor", new Color(255, 0,0));
targetObject.gameObject.GetComponent<MeshRenderer>().materials[0]
.SetColor("_EmissiveColor", new Color(255, 0, 0));
//Track if we have a close target
hasCloseTarget = true;
hasCloseTarget = true;
}
else
{
targetObject.gameObject.transform.position = transform.position + (ray.direction * maxTargetObjDistance);
targetObject.gameObject.GetComponent<MeshRenderer>().materials[0].SetColor("_EmissiveColor", new Color(255, 255,255));
targetObject.gameObject.transform.position =
transform.position + ray.direction * maxTargetObjDistance;
targetObject.gameObject.GetComponent<MeshRenderer>().materials[0]
.SetColor("_EmissiveColor", new Color(255, 255, 255));
//Track if we have a close target
hasCloseTarget = false;
}
//float drop = CalculateDrop(this.bulletSpawnPoint.position, hit.point, this.transform.up * this.firePower);
//print(drop);
}
else
{
targetObject.gameObject.transform.position = transform.position + (ray.direction * maxTargetObjDistance);
targetObject.gameObject.transform.position = transform.position + ray.direction * maxTargetObjDistance;
targetObject.gameObject.GetComponent<MeshRenderer>().materials[0].SetColor("_EmissiveColor", new Color(255,255,255));
targetObject.gameObject.GetComponent<MeshRenderer>().materials[0]
.SetColor("_EmissiveColor", new Color(255, 255, 255));
hasCloseTarget = false;
}
}
}
private float CalculateDrop(Vector3 origin, Vector3 destination, Vector3 force)
{
// Calculate the initial velocity required to reach the destination.
var displacement = destination - origin;
var time = Mathf.Sqrt(2f * displacement.magnitude / Physics.gravity.magnitude);
var velocity = (displacement - 0.5f * Physics.gravity * time * time) / time + force;
// Calculate the height the object will reach during its flight.
var maxHeight = origin.y + velocity.y * time - 0.5f * Physics.gravity.y * time * time;
// Calculate the distance the object will drop during its flight.
var dropDistance = maxHeight - destination.y;
return dropDistance;
}
public void Fire()
{
Fire(!hasCloseTarget);
@ -131,71 +128,62 @@ public class PistolComponent : MonoBehaviour
{
shootLightDuration = 0;
shootLight.gameObject.SetActive(true);
GameObject projectile = Instantiate(projectilePrefab, this.bulletSpawnPoint);
var projectile = Instantiate(projectilePrefab, bulletSpawnPoint);
projectile.transform.localPosition = Vector3.zero;
projectile.transform.localEulerAngles = Vector3.zero;
projectile.transform.localScale = Vector3.one;
Rigidbody pRigid = projectile.GetComponent<Rigidbody>();
var pRigid = projectile.GetComponent<Rigidbody>();
/*Modified targeting system
1. Since aim direction is vector from camera to ball (where player thinks its gonna go), raycast forward there, till hit. If no hit,
then set target distance to ~50.
2. Modify launch vector apply modified force
*/
Vector3 launchVector = pRigid.transform.up * this.firePower;
var launchVector = pRigid.transform.up * firePower;
if(offsetWithTargetBall||aimMode==AimMode.MODIFIED)
if (offsetWithTargetBall || aimMode == AimMode.MODIFIED)
{
Vector3 ballCamVector = targetObject.transform.position - this.GetComponentInParent<PlayerMovementController>().cam.transform.position;
Ray r = new Ray();
var ballCamVector = targetObject.transform.position -
GetComponentInParent<PlayerMovementController>().cam.transform.position;
var r = new Ray();
r.origin = targetObject.transform.position;
r.direction = ballCamVector.normalized;
RaycastHit hit;
if (Physics.Raycast(r,out hit,ignoreLayers))
if (Physics.Raycast(r, out hit, ignoreLayers))
{
launchVector = (hit.point - pRigid.transform.position).normalized;
launchVector *= this.firePower;
launchVector *= firePower;
}
}
else if(aimMode==AimMode.CAMERA)
else if (aimMode == AimMode.CAMERA)
{
Vector3 target = PlayerAim.active.targetPosition;
Vector3 lv = target - pRigid.transform.position;
var target = PlayerAim.active.targetPosition;
var lv = target - pRigid.transform.position;
launchVector = lv.normalized;
launchVector*= this.firePower;
launchVector *= firePower;
}
pRigid.AddForce(launchVector, ForceMode.Impulse);
projectile.transform.parent = null;
shootEffect.Play();
}
public void Enable()
{
IsEnabled = true;
if (targetObject == null)
{
targetObject = Instantiate(targetObjectPrefab);
}
if (targetObject == null) targetObject = Instantiate(targetObjectPrefab);
}
public void Disable()
{
IsEnabled = false;
if (targetObject != null)
{
Destroy(targetObject);
}
if (targetObject != null) Destroy(targetObject);
}
public void LightToggle() {
this.targetingLight.gameObject.SetActive(!this.targetingLight.gameObject.activeSelf);
public void LightToggle()
{
targetingLight.gameObject.SetActive(!targetingLight.gameObject.activeSelf);
}
public bool IsLightOn { get { return this.targetingLight.gameObject.activeSelf; } }
}
}