//Loops: private void Update() { RaycastHit hit; if (Physics.Raycast(controllerPose.position, controllerPose.forward, out hit)) { //adjust cursor: cursor.gameObject.SetActive(true); cursor.position = hit.point + hit.normal * surfaceOffset; cursor.rotation = Quaternion.LookRotation(hit.normal); //handle the surface we are hitting: switch (SurfaceDetails.Analyze(hit)) { case SurfaceType.Ceiling: status.text = "THE CEILING"; break; case SurfaceType.Floor: status.text = "THE FLOOR"; break; case SurfaceType.Seat: status.text = "A SEAT"; break; case SurfaceType.Table: status.text = "A TABLE TOP"; break; case SurfaceType.Underside: status.text = "UNDERSIDE"; break; case SurfaceType.Wall: status.text = "A WALL"; break; } } else { //adjust cursor: cursor.gameObject.SetActive(false); status.text = "NOTHING!"; } }
private void BounceOnSurface(RaycastHit hit, SurfaceDetails surface = null) { if (surface.gameObject.tag != "Vision") { bounceCount++; //reflect the bullet on the surface Vector3 newDir = Vector3.Reflect(transform.forward, hit.normal); transform.forward = newDir; shootInfo.dir = newDir; float speedLose = 0.20f; if (surface != null) { speedLose = surface.BulletsSpeedLoseOnBounce; } shootInfo.speed -= speedLose * shootInfo.speed; } }
//Loops: private void Update() { //used to orient the ceiling and floor visuals: Vector3 flatForward = Vector3.ProjectOnPlane(_camera.forward, Vector3.up); //set ceiling and floor visuals: if (SurfaceDetails.CeilingFound) { ceiling.position = new Vector3(_camera.position.x, SurfaceDetails.CeilingHeight, _camera.position.z); ceiling.rotation = Quaternion.LookRotation(Vector3.up, flatForward); } if (SurfaceDetails.FloorFound) { floor.position = new Vector3(_camera.position.x, SurfaceDetails.FloorHeight, _camera.position.z); floor.rotation = Quaternion.LookRotation(Vector3.down, flatForward); } RaycastHit hit; if (Physics.Raycast(controllerPose.position, controllerPose.forward, out hit)) { //adjust cursor: cursor.gameObject.SetActive(true); cursor.position = hit.point + hit.normal * surfaceOffset; cursor.rotation = Quaternion.LookRotation(hit.normal); //handle the surface we are hitting: switch (SurfaceDetails.Analyze(hit)) { case SurfaceType.Ceiling: status.text = "THE CEILING"; break; case SurfaceType.Floor: status.text = "THE FLOOR"; break; case SurfaceType.Seat: status.text = "A SEAT"; break; case SurfaceType.Table: status.text = "A TABLE TOP"; break; case SurfaceType.Underside: status.text = "UNDERSIDE"; break; case SurfaceType.Wall: status.text = "A WALL"; break; } } else { //adjust cursor: cursor.gameObject.SetActive(false); status.text = "NOTHING!"; } }
private void Update() { if (!launched) { return; } if (shouldHit) { if (shootInfo.hitEffect != null) { Instantiate(shootInfo.hitEffect, transform.position, Quaternion.identity); } Destroy(gameObject); return; } float travelDistance = Time.deltaTime * shootInfo.speed; distanceTraveled += travelDistance; RaycastHit hit; bool hitSomething = Physics.Raycast(transform.position, transform.forward, out hit, travelDistance, shootInfo.hitLayer.value); if (hitSomething) //&& hit.collider != playerCollider) { transform.position += transform.forward * hit.distance; bool handleByDamageSystem = TryDoDamage(hit.collider); //if we hit a object that dont process the damage in his on way using Damageable components, add just the impact force in a default way if (!handleByDamageSystem) { ApplyImpactForce(hit.rigidbody, hit.point); } SurfaceDetails surface = hit.collider.GetComponent <SurfaceDetails>(); if (surface != null) { if (surface.BulletsCanBounce && bounceCount < shootInfo.maxBounceCount) { BounceOnSurface(hit, surface); } else { shouldHit = true; } } else if (bounceCount < shootInfo.maxBounceCount) { BounceOnSurface(hit, null); } else { shouldHit = true; } } else { transform.position += shootInfo.dir * travelDistance; if (distanceTraveled >= shootInfo.range) { Destroy(gameObject); } } }