// Update is called once per frame void Update() { // angle += 45 * Time.deltaTime; float distance = 5.5f; //Angle Target to rotate box Quaternion angleAxis = Quaternion.AngleAxis(-angle, Vector3.up); Vector3 angleDirection = transform.position + (transform.forward * distance); Vector3 angleTarget = RotateAroundPoint(angleDirection, transform.position, angleAxis); //Projection of the box Vector3 origin = transform.position; Vector3 halfExtents = Vector3.one / 2f; Vector3 direction = angleTarget - origin; //Transform.forward Quaternion orientation = Quaternion.LookRotation(direction); //Transform.rotation RaycastHit hitInfo; if (Physics.BoxCast(origin, halfExtents, direction, out hitInfo, orientation, distance)) { ExtDebug.DrawBoxCastOnHit(origin, halfExtents, orientation, direction, hitInfo.distance, Color.red); } ExtDebug.DrawBoxCastBox(origin, halfExtents, orientation, direction, distance, Color.green); }
public bool IsHitForwad(float distance, out PlayerController hitPlayer, CampTeam team) { bool result = false; PlayerController hitedPlayer = null; Vector3 origem = transform.position + (transform.forward * 1.0f); Vector3 halfExtents = Vector3.one / 2f; Vector3 direction = transform.forward; Quaternion orientation = transform.rotation; RaycastHit hitInfo; if (Physics.BoxCast(origem, halfExtents, direction, out hitInfo, orientation, distance, LayerMask.GetMask("SoccerPlayer"))) { if (hitInfo.transform.GetComponent <PlayerController>() != null) { hitedPlayer = hitInfo.transform.GetComponent <PlayerController>(); if (hitedPlayer.GetCampTeam() == team && hitedPlayer.isOk) { result = true; } ExtDebug.DrawBoxCastOnHit(origem, halfExtents, orientation, direction, hitInfo.distance, Color.red); } //ExtDebug.DrawBoxCastOnHit(origem, halfExtents, orientation, direction, hitInfo.distance, Color.red); } //ExtDebug.DrawBox(origem, halfExtents, orientation, Color.red); hitPlayer = hitedPlayer; return(result); }
private void FixedUpdate() { Vector3 pos = this.transform.position + Vector3.up * coll.center.y; ExtDebug.DrawBoxCastOnHit(pos, coll.bounds.extents, this.transform.rotation, transform.forward, RaycastLength, Color.red); CheckIfPlayerIsNear(); }
// Update is called once per frame void Update() { RaycastHit haut; float rcGoomba = 0.35f; //this.animator.Play("Agrandir"); //AnimatorStateInfo state = anim.GetCurrentAnimatorStateInfo(0); //Debug.Log(this.animator.GetCurrentAnimatorStateInfo(0).ToString()); //Debug.Log (this.animator.GetCurrentAnimatorStateInfo(0).IsName("Agrandir")); /* if (this.animator.GetCurrentAnimatorStateInfo(0).IsName("Agrandir") ) * { * Debug.Log("est en train de grandir"); * taille = 1f; * * } */ /* * Debug.DrawRay ( transform.position + new Vector3(0f,taille,0f),transform.forward , Color.red); * if (Physics.Raycast (transform.position+ new Vector3(0f,taille,0f), transform.forward, out devant, rcGoomba)) { * //Debug.Log("ici" ); * if (devant.transform.tag=="Player") { * * // Destroy (devant.transform.gameObject); * * } * } * Debug.DrawRay (transform.position + new Vector3(0f,taille,0f), -transform.forward, Color.red); * if (Physics.Raycast (transform.position+ new Vector3(0f,taille,0f), -transform.forward, out derriere, rcGoomba)) { * * if (derriere.transform.tag=="Player") { * * // Destroy (derriere.transform.gameObject); * * } * }*/ Vector3 newPos = new Vector3(transform.position.x, transform.localScale.y, transform.position.z); newPos.y = newPos.y * adjustextension; newPos = newPos + new Vector3(0f, transform.position.y, 0f); // adjustement de la boxcast ExtDebug.DrawBoxCastOnHit(newPos, new Vector3(longueurHaut, longueurHaut, longueurHaut), Quaternion.identity, transform.up, rcGoomba, Color.red); if (Physics.BoxCast(newPos, new Vector3(longueurHaut, longueurHaut, longueurHaut), transform.up, out haut, Quaternion.identity, rcGoomba)) { Debug.Log("touche haut"); if (haut.transform.tag == "Player") { haut.transform.GetComponent <mvt>().degat(); Debug.Log("Le Mario Meurt"); //Destroy(haut.transform.gameObject); //Destroy (derriere.transform.gameObject); } } }
private void FixedUpdate() { //+ new Vector3(rcLongueur, rcTaille, framelongueur) if (this.gameObject.tag.Equals("Champi")) { ExtDebug.DrawBoxCastOnHit(transform.position + new Vector3(rcLongueur, rcTaille + 0.5f, framelongueur), new Vector3(longueurHaut, longueurHaut, longueurHaut) / 2, Quaternion.identity, transform.up, 1.0f, Color.red); if (Physics.BoxCast(transform.position + new Vector3(rcLongueur, rcTaille + 0.5f, framelongueur), new Vector3(longueurHaut, longueurHaut, longueurHaut), transform.up, out triggerTete, Quaternion.identity, 1)) { if (triggerTete.transform.tag.Equals("Player")) { if (this.gameObject.tag.Equals("Champi")) { triggerTete.transform.GetComponent <Questionb>().MarioDevienGrand(true); } Destroy(this.gameObject); } } } if (this.gameObject.tag.Equals("piece")) { ExtDebug.DrawBoxCastOnHit(transform.position + new Vector3(0, 1, 0), new Vector3(longueurHaut, longueurHaut, longueurHaut) / 2, Quaternion.identity, transform.forward, 1.0f, Color.red); if (Physics.BoxCast(transform.position + new Vector3(0, 1, 0), new Vector3(longueurHaut, longueurHaut, longueurHaut), transform.forward, out triggerTete, Quaternion.identity, 1)) { if (triggerTete.transform.tag.Equals("Player")) { if (Global.isMulti) { if (triggerTete.transform.gameObject.GetComponent <mvt>().getIsMine()) { Global.score++; Debug.Log("Il s'agit d'une piece"); } } else { Global.score++; Debug.Log("Il s'agit d'une piece2"); } Destroy(this.gameObject); } } } }
bool RaycastForObstacle() { RaycastHit hit; Vector3 pos = this.transform.position + Vector3.up * coll.center.y; ExtDebug.DrawBoxCastOnHit(pos, coll.bounds.extents, this.transform.rotation, transform.forward, RaycastLength, Color.red); if (Physics.BoxCast(pos, coll.bounds.extents, transform.forward, out hit, this.transform.rotation, RaycastLength, ~(1 << LayerMask.NameToLayer("Animal")))) { if (hit.collider != null) { return(true); } } return(false); }
void CheckForObstruction() { Collider[] colls; ExtDebug.DrawBoxCastOnHit(this.transform.position, coll.bounds.extents * 1.3f, this.transform.rotation, transform.forward, 0, Color.red); colls = Physics.OverlapBox(this.transform.position, coll.bounds.extents * 1.3f, this.transform.rotation, ~(1 << this.gameObject.layer)); if (colls.Length > 0) { this.audio.PlayOneShot(errorPlacement); CanPlace = false; } else { CanPlace = true; } //Debug.Log("Can Place: " + CanPlace); }
} // End Move override public System.Nullable<RaycastHit> Cast(Vector3 direction, float distance) { bool hit; RaycastHit hitInfo; hit = Physics.BoxCast( hitInfo: out hitInfo, center: transform.position, halfExtents: castBoxSize, direction: direction, layerMask: collisionMask.constValue, orientation: transform.rotation, queryTriggerInteraction: QueryTriggerInteraction.Ignore, maxDistance: distance ); #if UNITY_EDITOR if(debugCasts.constValue) { ExtDebug.DrawBoxCastBox( origin: transform.position, halfExtents: castBoxSize, orientation: transform.rotation, direction: direction, distance: distance, duration: debugCastLifetime, color: (hit ? debugCastAttempt : debugCastMiss) ); if(hit) { ExtDebug.DrawBoxCastOnHit( origin: transform.position, halfExtents: castBoxSize, orientation: transform.rotation, direction: direction, hitInfoDistance: hitInfo.distance, duration: debugCastLifetime, color: debugCastHit ); } } #endif return new System.Nullable<RaycastHit>(hitInfo); } // End Cast
} // End Cast override public RaycastHit[] CastAll(Vector3 direction, float distance) { RaycastHit[] hitInfoAr; hitInfoAr = Physics.BoxCastAll( center: transform.position, halfExtents: castBoxSize, direction: direction, layerMask: collisionMask.constValue, orientation: transform.rotation, queryTriggerInteraction: QueryTriggerInteraction.Ignore, maxDistance: distance ); #if UNITY_EDITOR if(debugCasts.constValue) { ExtDebug.DrawBoxCastBox( origin: transform.position, halfExtents: castBoxSize, orientation: transform.rotation, direction: direction, distance: distance, duration: debugCastLifetime, color: (hitInfoAr.Length > 0 ? debugCastAttempt : debugCastMiss) ); foreach(RaycastHit hitInfo in hitInfoAr) { ExtDebug.DrawBoxCastOnHit( origin: transform.position, halfExtents: castBoxSize, orientation: transform.rotation, direction: direction, hitInfoDistance: hitInfo.distance, duration: debugCastLifetime, color: debugCastHit ); } } #endif return hitInfoAr; } // End CastAll
private bool IsOpenForMove(Vector3 direction, float distance) { RaycastHit hitInfo; var capsuleCollider = GetComponent <CapsuleCollider>(); var boxDimensions = new Vector3(capsuleCollider.radius, capsuleCollider.height / 2 * 0.9f, capsuleCollider.radius); boxDimensions.Scale(transform.localScale); var hit = Physics.BoxCast( transform.position, boxDimensions, direction, out hitInfo, Quaternion.identity, distance, CastMask, QueryTriggerInteraction.Ignore); if (IsDebug) { if (hit) { hitInfo.collider.gameObject.GetComponent <Block>().AnimateBlocked(); } ExtDebug.DrawBoxCastOnHit( transform.position, boxDimensions, Quaternion.identity, direction, distance, Color.blue); } return(!hit); }
private void FixedUpdate() { RaycastHit hit; RaycastHit hitAv; RaycastHit hitAr; RaycastHit hitB; Debug.DrawRay(transform.position, transform.up * rcTailleHaut, Color.red); Debug.DrawRay(transform.position, -transform.up * rcTailleBas, Color.yellow); Debug.DrawRay(transform.position, transform.right * rcTailleDirection, Color.green); Debug.DrawRay(transform.position, -transform.right * rcTailleDirection, Color.blue); if (Physics.Raycast(transform.position, transform.up, out hit, rcTailleHaut)) { if (hit.transform.name.Equals("box")) { Destroy(hit.transform.gameObject); } } toucheSol = GetComponent <CharacterController>().isGrounded; if (Physics.Raycast(transform.position, -transform.up, out hit, rcTailleBas))// /0.5 { if (hit.transform.tag.Equals("Goomba")) { Debug.Log("le goomba est mort"); } /* * if (hit.transform.tag.Equals("Sol")) * { * * toucheSol = true; * * } * else * { * * toucheSol = false; * } */ } ExtDebug.DrawBoxCastOnHit(transform.position + new Vector3(0f, rcTailleHaut, 0f), new Vector3(longueurHaut, longueurHaut, longueurHaut) / 2, Quaternion.identity, transform.up, 1.0f, Color.red); if (Physics.BoxCast(transform.position + new Vector3(0f, rcTailleHaut, 0f), new Vector3(longueurHaut, longueurHaut, longueurHaut), transform.up, out triggerTete, Quaternion.identity, 1)) { if (triggerTete.transform.tag.Equals("MysteryBlock")) { triggerTete.transform.GetComponent <MysteryBoxScript>().touche(); } if (triggerTete.transform.tag.Equals("Brique")) { if (marioGrand) { Destroy(triggerTete.transform.gameObject); Global.score++; } } } }
void FixedUpdate() { if (!isMort) { RaycastHit rcMort; RaycastHit haut; Vector3 pos = transform.position; if (test) { Debug.Log("movingRight:" + movingRight); } if (movingRight) { if (pos.x > origin.x + distance) { transform.Rotate(0, 180, 0, Space.World); movingRight = false; } else { pos.x += Time.deltaTime * speed; transform.position = pos; } } else { if (pos.x < origin.x - distance) { transform.Rotate(0, 180, 0, Space.World); movingRight = true; } else { pos.x -= Time.deltaTime * speed; transform.position = pos; } } Vector3 newPos = new Vector3(pos.x, pos.y + adjust, pos.z); Vector3 newPos2 = new Vector3(pos.x, pos.y + adjust2, pos.z); //Faire que ca desactive la mort de goomba quand Mario touche et meurt car il peut traverser et le tuer. ExtDebug.DrawBoxCastOnHit(newPos, new Vector3(longueurHaut, longueurHaut, longueurHaut), Quaternion.identity, transform.up * -1f, rcGoomba, Color.red); if (Physics.BoxCast(newPos, new Vector3(longueurHaut, longueurHaut, longueurHaut), transform.up * -1f, out haut, Quaternion.identity, rcGoomba)) { if (haut.transform.tag == "Player") { Debug.Log("mario se prend des degats dans GoombaMove"); haut.transform.GetComponent <mvt>().degat(); //Destroy(haut.transform.gameObject); //Destroy (derriere.transform.gameObject); } } ExtDebug.DrawBoxCastOnHit(transform.position + new Vector3(0f, 0.2f, 0f), new Vector3(longueurHaut2, longueurHaut2, longueurHaut2), Quaternion.identity, transform.up, rMort, Color.blue); if (Physics.BoxCast(transform.position + new Vector3(0f, 0.2f, 0f), new Vector3(longueurHaut2, longueurHaut2, longueurHaut2), transform.up, out rcMort, Quaternion.identity, rMort)) { if (rcMort.transform.tag == "Player") { isMort = true; Debug.Log("Le Goomba Meurt"); anim.SetBool("isMort", true); StartCoroutine(attenteFinAnimation()); //Destroy(this.gameObject); //Destroy (derriere.transform.gameObject); } } } }