void Shoot() { RaycastHit hit; if (!charger.Discharge(damage / 10f)) { return; } muzzleFlash.Play(); fire.Play(0); if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { if (hit.collider.tag == "Enemy") { hit.collider.GetComponent <Health>().TakeDamage(damage); //hit.normal //Instantiate(hitAnim,hit.point,Quaternion.LookRotation(hit.normal)); //Debug.DrawRay(transform.position, transform.position + (transform.forward * range), Color.red); } if (hit.collider.tag == "Vegetation") { hit.collider.GetComponent <Health>().TakeDamage(damage); //Debug.DrawRay(transform.position, transform.position + (transform.forward * range), Color.red); } } }
void Move() { if (health.isDead) { return; } // Do not add force if out of charge or at top speed if ((!charger.HasCharge(chargeBurnRate * Time.deltaTime)) || currentSpeed >= topSpeed) { return; } Vector3 fwd = (racer.forward * forwardThrust + racer.right * sideThrust); fwd = new Vector3(fwd.x, 0, fwd.z); fwd.Normalize(); rb.AddForce(fwd * Time.deltaTime * speedMultiplier, ForceMode.VelocityChange); if (fwd.magnitude > 0f) { charger.Discharge(chargeBurnRate * Time.deltaTime); } }