void Work_Vision() { RaycastHit2D[] alh; if (Target != null) { SeeLine = true; Vector3 TargetVec = Target.pos - Me.pos; float TargetDist = TargetVec.magnitude; if (TargetDist < SeeRad) { alh = Physics2D.RaycastAll(Me.pos, TargetVec, TargetDist); foreach (RaycastHit2D go in alh) { if (go.collider.transform.GetComponent <Solid2D>()) { Solid2D wrk = go.collider.transform.GetComponent <Solid2D>(); if (!wrk.Platform) { SeeLine = false; break; } } } } } }
//private void OnCollisionEnter2D(Collision2D cos) //{ // // H_MySolids.Clear(); // // OnGround = false; // Debug.Log("FUFUFUUFU"); // foreach (ContactPoint2D go in cos.contacts) // { // Solid2D wrk = go.collider.transform.GetComponent<Solid2D>(); // // if(wrk != null && go.point.y - R_MyPos.y <= StepOffset+ BaseRad) // if (wrk != null && H_CloseSolids.Contains(wrk)) // { // bool AddWrk = true; // if(wrk.Platform) // { // if (LF_IgnorPlatform(wrk)) // { // AddWrk = false; // } // } // if (AddWrk) // { // if (!H_MySolids.Contains(wrk)) // { // H_MySolids.Add(wrk); // OnGround = true; // } // } // } // } //} //private void OnCollisionExit2D(Collision2D cos) //{ // H_MySolids.Clear(); // OnGround = false; // foreach (ContactPoint2D go in cos.contacts) // { // Solid2D wrk = go.collider.transform.GetComponent<Solid2D>(); // if (wrk != null && go.point.y - R_MyPos.y <= StepOffset + BaseRad) // { // bool AddWrk = true; // if (wrk.Platform) // { // if (LF_IgnorPlatform(wrk)) // { // AddWrk = false; // } // } // if (AddWrk) // { // if (!H_MySolids.Contains(wrk)) // { // H_MySolids.Add(wrk); // OnGround = true; // } // } // } // } //} private void OnCollisionStay2D(Collision2D cos) { //H_MySolids.Clear(); //OnGround = false; foreach (ContactPoint2D go in cos.contacts) { Solid2D wrk = go.collider.transform.GetComponent <Solid2D>(); if (wrk != null && H_CloseSolids.Contains(wrk)) { bool AddWrk = true; if (wrk.Platform) { if (LF_IgnorPlatform(wrk)) { AddWrk = false; } } if (AddWrk) { if (!H_MySolids.Contains(wrk)) { H_MySolids.Add(wrk); OnGround = true; } } } } }
bool LF_CheckStepForHole(Unit Stepper, float MovDir) { bool rezult = false; float CheckStepDist = Stepper.mov.BaseRad * 4f; RaycastHit2D[] AllHits = Physics2D.CircleCastAll(Stepper.pos + Vector3.up * Stepper.mov.BaseRad + Vector3.right * MovDir * CheckStepDist, Stepper.mov.BaseRad, Vector3.down, Stepper.prm.MaxJumpHeight * 1.2f); RaycastHit2D ClossestHit = new RaycastHit2D(); ClossestHit.distance = Stepper.prm.MaxJumpHeight * 2f; foreach (RaycastHit2D GoHit in AllHits) { Solid2D WorkSolid = GoHit.transform.GetComponent <Solid2D>(); if (WorkSolid != null && WorkSolid.GetComponentInParent <Unit>() != Stepper) { if (GoHit.distance < ClossestHit.distance) { ClossestHit = GoHit; } } } if (ClossestHit.distance > 0.9f * Stepper.prm.MaxJumpHeight) { rezult = true; } return(rezult); }
bool LF_CheckMoveSpace(Unit Mover, float HorDir) { float CheckRad = Mover.mov.BaseRad; float CheckDist = 5f; RaycastHit2D[] AllHits = Physics2D.CircleCastAll(Mover.pos + Vector3.up * CheckRad * 1.05f, CheckRad, Vector3.right * HorDir, CheckDist); RaycastHit2D ClossestHit = new RaycastHit2D(); ClossestHit.distance = CheckDist * 2f; foreach (RaycastHit2D GoHit in AllHits) { Solid2D WorkSolid = GoHit.transform.GetComponent <Solid2D>(); if (WorkSolid != null && WorkSolid.GetComponentInParent <Unit>() != Mover) { if (GoHit.distance < ClossestHit.distance) { ClossestHit = GoHit; } } } TempToolPoint = ClossestHit.point; bool rezult = false; if (Mathf.Abs(Mover.pos.x - ClossestHit.point.x) > Mover.mov.BaseRad * 2f || ClossestHit.normal.y > 0.1f) { rezult = true; } return(rezult); }
float LF_CheckHoleSize(Unit Jumper, float HorDir) { float CheckRad = 0.1f; RaycastHit2D[] AllHits = Physics2D.CircleCastAll(Jumper.pos, CheckRad, Vector3.right * HorDir, Jumper.prm.MaxJumpDist * 1.5f); RaycastHit2D ClossestHit = new RaycastHit2D(); ClossestHit.distance = Jumper.prm.MaxJumpDist * 2f; ClossestHit.point = Jumper.pos + Vector3.right * HorDir * 99f; foreach (RaycastHit2D GoHit in AllHits) { Solid2D WorkSolid = GoHit.transform.GetComponent <Solid2D>(); if (WorkSolid != null && WorkSolid.GetComponentInParent <Unit>() != Jumper) { if (Mathf.Abs(GoHit.point.x - Jumper.pos.x) > Jumper.mov.BaseRad) { if (GoHit.distance < ClossestHit.distance) { ClossestHit = GoHit; } } } } float rezult = Mathf.Abs(ClossestHit.point.x - Jumper.pos.x); return(rezult); }
void WorkMove() { RaycastHit2D[] alh; if (Me.mov.OnGround) { Vector3 point = Me.pos + Vector3.right * WantedMoveDir * CheckRad * 2f + Vector3.up * CheckRad * 2f; alh = Physics2D.CircleCastAll(point, CheckRad, Vector2.down); RaycastHit2D Closst = new RaycastHit2D(); Closst.distance = 33f; foreach (RaycastHit2D go in alh) { if (go.collider.transform.GetComponent <Solid2D>() && go.collider.transform.GetComponentInParent <Unit>() != Me) { Solid2D wrk = go.collider.transform.GetComponent <Solid2D>(); if (Closst.distance > go.distance) { Closst = go; } } } if (Closst.distance < CheckRad + Me.mov.StepOffset * 2f) { Me.mov.In_HorDir = WantedMoveDir; } else { Debug.Log("Stop"); Me.mov.In_HorDir = 0; } } }
void LF_CheckSurf(Vector2 strt, float rad) { RaycastHit2D[] hit = Physics2D.CircleCastAll(strt, rad, Vector2.down, 200f); TempHit.distance = 222f; foreach (RaycastHit2D goh in hit) { if (goh.collider.transform.GetComponent <Solid2D>()) { Solid2D wrk = goh.collider.transform.GetComponent <Solid2D>(); if (wrk.transform.GetComponentInParent <U_Mov2D>() != this) { if (TempHit.distance > goh.distance) { if (!wrk.Platform || (wrk.Platform && ActvPls.Contains(wrk))) { TempHit = goh; } } } } } TempAngl = 90 - Vector2.Angle(TempHit.normal, Vector2.right); }
public override bool IsRiding(Solid2D solid) { // We just need to check if our Collider Bottom Edge is the same as the Solid Top Edge // and we are not at its left or its right bool isAtLeft = collider.Right < solid.collider.Left; bool isAtRight = collider.Left > solid.collider.Right; return((Math.Abs(collider.Bottom - solid.collider.Top) == 0) && !isAtLeft && !isAtRight); }
RaycastHit2D LF_DoRay(Vector3 point, Vector3 dir, float rad, float Dist, bool spec) { RaycastHit2D RezHit = new RaycastHit2D(); RezHit.distance = 2 * Dist; RezHit.point = point + dir * (rad + Dist); RaycastHit2D[] alh = Physics2D.CircleCastAll(point, rad, dir, Dist); foreach (RaycastHit2D hit in alh) { Solid2D wrk = hit.collider.transform.GetComponent <Solid2D>(); if (wrk != transform.GetComponentInChildren <Solid2D>()) { bool Ignor = true; if (wrk != null) { if (wrk.Platform) { Ignor = LF_IgnorPlatform(wrk); } else { Ignor = false; } if (hit.point.y - R_MyPos.y > StepOffset) { Ignor = true; } if (spec) { // Debug.Log(hit.distance + hit.collider.gameObject.name); if (hit.distance <= StepOffset * 1.1f) { H_CloseSolids.Add(wrk); } } } if (!Ignor) { if (RezHit.distance > hit.distance) { RezHit = hit; } } } } return(RezHit); }
private void OnTriggerStay2D(Collider2D col) { GrndCnt = 0; if (col.transform.GetComponent <Solid2D>()) { Solid2D wrk = col.transform.GetComponent <Solid2D>(); if (wrk.Platform) { if (!NoPlatform) { if (!Platforms.Contains(wrk)) { Platforms.Add(wrk); } if (ActvPls.Contains(wrk)) { if (!Grnds.Contains(wrk)) { GrndCnt++; Grnds.Add(wrk); } else { GrndCnt++; } } } } else { if (!Grnds.Contains(wrk)) { Grnds.Add(wrk); GrndCnt++; } else { GrndCnt++; } } if (GrndCnt > 0) { OnGrnd = true; } } }
private void OnTriggerExit2D(Collider2D col) { Solid2D wrk = col.transform.GetComponent <Solid2D>(); if (wrk != null) { if (H_MySolids.Contains(wrk)) { H_MySolids.Remove(wrk); if (H_MySolids.Count <= 0) { OnGround = false; } } } }
private void OnTriggerExit2D(Collider2D col) { if (col.transform.GetComponent <Solid2D>()) { Solid2D wrk = col.transform.GetComponent <Solid2D>(); if (Grnds.Contains(wrk)) { Grnds.Remove(wrk); } GrndCnt--; if (GrndCnt <= 0) { OnGrnd = false; } if (wrk.Platform && Platforms.Contains(wrk)) { Platforms.Remove(wrk); } } }
void LF_CheckPlatforms() { ActvPls.Clear(); if (!NoPlatform) { RaycastHit2D[] hit = Physics2D.CircleCastAll(MyPos + Vector2.up * TestRad * 2f, TestRad, Vector2.down, TestRad * 3); foreach (RaycastHit2D goh in hit) { if (goh.collider.transform.GetComponent <Solid2D>()) { Solid2D wrk = goh.collider.transform.GetComponent <Solid2D>(); if (Platforms.Contains(wrk)) { if (goh.distance >= TestRad) { ActvPls.Add(wrk); } } } } } }
bool LF_IgnorPlatform(Solid2D platform) { Vector3 LoPo = platform.transform.InverseTransformPoint(R_MyPos); if (LoPo.y < 0) { return(true); } if (LoPo.y < BaseRad) { if (Mathf.Abs(LoPo.x) - (0.5f) < 0) { // Debug.Log("GOV"+LoPo); return(true); } Vector3 pnt = platform.transform.GetComponent <EdgeCollider2D>().points[0]; if (LoPo.x > 0) { pnt = platform.transform.GetComponent <EdgeCollider2D>().points[1]; } float Dist = (LoPo - pnt).sqrMagnitude; if (Mathf.Abs(LoPo.x) - (0.5f + BaseRad * 1.01f) >= 0 && Dist < (BaseRad * BaseRad) * 1.01f) { return(true); } else { return(false); } } return(false); }
public override bool IsRiding(Solid2D solid) { return(false); }
void LF_SurfaceWork() { float CastStepOffset = BaseRad * 0.5f; float CastDist = 5f; Vector3 cpoint = R_MyPos + Surfacer.up * (StepOffset);//убрал отсюда базовый радиус H_CloseSolids.Clear(); RaycastHit2D chit = LF_DoRay(cpoint, -Surfacer.up, BaseRad, CastDist, true); Vector3 rpoint = cpoint + Surfacer.right * CastStepOffset; RaycastHit2D rhit = LF_DoRay(rpoint, -Surfacer.up, BaseRad, CastDist, false); Vector3 lpoint = cpoint - Surfacer.right * CastStepOffset; RaycastHit2D lhit = LF_DoRay(lpoint, -Surfacer.up, BaseRad, CastDist, false); for (int lo = H_MySolids.Count - 1; lo >= 0; lo--) { Solid2D go = H_MySolids[lo]; if (!H_CloseSolids.Contains(go)) { H_MySolids.RemoveAt(lo); } } if (H_MySolids.Count <= 0) { OnGround = false; } //cpoint += -Surfacer.up * chit.distance; нужная точка rdir = rpoint - (Surfacer.up * rhit.distance) - (cpoint - Surfacer.up * (chit.distance)); rdir = rdir.normalized; float rangl = Vector3.Angle(rdir, Surfacer.right); if (Surfacer.InverseTransformDirection(rdir).y < 0) { rangl = -rangl; } Debug.DrawLine(rpoint - (Surfacer.up * rhit.distance), cpoint - Surfacer.up * (chit.distance), Color.red, 0.1f); ldir = lpoint - (Surfacer.up * lhit.distance) - (cpoint - Surfacer.up * (chit.distance)); ldir = ldir.normalized; float langl = Vector3.Angle(ldir, -Surfacer.right); if (Surfacer.InverseTransformDirection(ldir).y > 0) { langl = -langl; } float cangl = Vector3.Angle(chit.normal, Surfacer.up); if (Surfacer.InverseTransformDirection(chit.normal).x > 0) { cangl = -cangl; } cdir.y = -chit.normal.x; cdir.x = chit.normal.y * (Mathf.Abs(chit.normal.x) / chit.normal.x); H_Angls.x = langl; H_Angls.y = cangl; H_Angls.z = rangl; }
List <Vector3> LF_FindReachebleHeights(Vector3 CheckPoint, Unit Jumper) { RaycastHit2D[] AllHits = Physics2D.CircleCastAll(Me.pos + Vector3.up * Me.mov.BaseRad, Me.mov.BaseRad * 0.8f, Vector3.up, Me.prm.MaxJumpHeight + Me.UnitHeight); RaycastHit2D Clossest = new RaycastHit2D(); Clossest.distance = (Me.prm.MaxJumpHeight + Me.UnitHeight) * 2f; Clossest.point = Me.pos + Vector3.up * 100f; foreach (RaycastHit2D go in AllHits) { Solid2D WorkSolid = go.transform.GetComponent <Solid2D>(); if (WorkSolid != null && WorkSolid.GetComponentInParent <Unit>() != Jumper) { if (go.distance < Clossest.distance) { Clossest = go; } } } List <Vector3> rezult = new List <Vector3>(); float CheckRad = Jumper.UnitHeight * 0.5f; float MaxHeight = Jumper.prm.MaxJumpHeight; AllHits = Physics2D.CircleCastAll(CheckPoint + Vector3.up * (MaxHeight + Jumper.UnitHeight), CheckRad, Vector3.down, MaxHeight * 1.5f); List <Vector3> TempPointList = new List <Vector3>(); foreach (RaycastHit2D GoHit in AllHits) { Solid2D WorkSolid = GoHit.transform.GetComponent <Solid2D>(); if (WorkSolid != null && WorkSolid.GetComponentInParent <Unit>() != Jumper) { Vector3 GoPoint = GoHit.point; TempPointList.Add(GoPoint); } } foreach (Vector3 GoPoint in TempPointList) { bool PassPoint = true; Collider2D[] AllCols = Physics2D.OverlapCircleAll(GoPoint + Vector3.up * CheckRad * 1.05f, CheckRad); foreach (Collider2D GoCol in AllCols) { Solid2D WorkSolid = GoCol.transform.GetComponent <Solid2D>(); if (WorkSolid != null) { PassPoint = false; } } if (GoPoint.y + Me.UnitHeight * 1.1f > Clossest.point.y) { PassPoint = false; } if (PassPoint) { rezult.Add(GoPoint); } } return(rezult); }