void OnCollisionEnter(Collision other) { if (ignoreLayers == (ignoreLayers | 1 << other.gameObject.layer)) { return; } else { if (other.gameObject.GetComponent <hitTarget> () != null) { hitTarget target = other.gameObject.GetComponent <hitTarget> (); if (!target.gotHit) { target.hit(damage); } } else if (other.gameObject == player.mainPlayer.gameObject) { player p = other.gameObject.GetComponent <player> (); p.hit(damage); Vector3 dir = other.contacts [0].point - gameObject.transform.position; dir = dir.normalized; other.gameObject.GetComponent <Rigidbody> ().AddForce(dir * knockbackForce); } } }
public void ActivateSnowball(Vector3 _target, float distance, hitTarget aimedAt) { Destroy(gameObject, 1.5f); target = _target; isActive = true; this.aimedAt = aimedAt; }
void OnTriggerStay(Collider other) { if (ignoreLayers == (ignoreLayers | 1 << other.gameObject.layer)) { return; } else { if (other.GetComponent <hitTarget> () != null) { hitTarget target = other.GetComponent <hitTarget> (); if (!target.gotHit) { target.hit(damage); } } } }
public void updatePosition(float thumbUp, float thumbLeft, float leftThumbVertical) { //thumbUp is the Left Thumbstick Vertical, thumbLeft is Left Thumbstick Horizontal //handle dampening of input variables float dampenedUp = 0, dampenedLeft = 0, dampenedRight = 0, threshold = 0.1f; if (thumbUp > 0) { if (thumbUp < threshold) { dampenedUp = 0; } else { dampenedUp = thumbUp; } } else if (thumbUp < 0) { if (thumbUp > (-1 * threshold)) { dampenedUp = 0; } else { dampenedUp = thumbUp; } } if (thumbLeft > 0) { if (thumbLeft < threshold) { dampenedLeft = 0; } else { dampenedLeft = thumbLeft; } } else if (thumbLeft < 0) { if (thumbLeft > (-1 * threshold)) { dampenedLeft = 0; } else { dampenedLeft = thumbLeft; } } if (leftThumbVertical > 0) { if (leftThumbVertical < threshold) { dampenedRight = 0; } else { dampenedRight = leftThumbVertical; } } else if (leftThumbVertical < 0) { if (leftThumbVertical > (-1 * threshold)) { dampenedRight = 0; } else { dampenedRight = leftThumbVertical; } } //debug variables forceLeft = dampenedLeft; forceUp = dampenedUp; rigid.AddForce(gameObject.transform.up * dampenedUp * multiplier); Debug.DrawLine(gameObject.transform.forward, gameObject.transform.forward * 10); rigid.AddForce(gameObject.transform.right * -1 * dampenedLeft * multiplier); //Add Vertical force if (gameObject.transform.position.y < distanceThreshold) { rigid.AddForce(Vector3.up * rigid.mass * dampenedRight); } else if (dampenedRight < 0) { rigid.AddForce(Vector3.up * rigid.mass * dampenedRight); } //Cast Target Object Ray rayfire = new Ray(OVRCamera.transform.position, OVRCamera.transform.forward); //10000000011 in base 10 int mask = 1027; if (Physics.Raycast(rayfire, out rayHit, 100, mask, QueryTriggerInteraction.Ignore)) { if (rayHit.collider.gameObject.layer == 8) { Debug.Log("Hit UFO"); } else { if (targetScript == null) { targetScript = hitTarget.GetComponent <hitTarget>(); targetScript.colorUpdate(rayHit); } else { targetScript.colorUpdate(rayHit); } } } }