//行为:攀爬移动 private void Climb() { //1.在触手体方向+生物移动方向上,寻找可抓取位置,修改当前抓取目标点 float fac = Utils.LerpMap(daddy.stuckCounter, 50f, 200f, 0.5f, 0.95f); //理想抓取位置 通过触手体当前方向 和 生物体MoveDirection 球形插值计算出来 this.idealGrabPos = this.FloatBase + (Vector2)Vector3.Slerp(tentacleDir, daddy.moveDirection, fac) * this.idealLength * 0.7f; //理想抓取方向 Vector2 idealGrabDir = this.FloatBase + (Vector2)Vector3.Slerp(Vector3.Slerp(tentacleDir, daddy.moveDirection, fac), Utils.RNV(), Mathf.InverseLerp(20f, 200f, foundNoGrabPos)) * this.idealLength * Utils.LerpMap(Math.Max(this.foundNoGrabPos, this.daddy.stuckCounter), 20f, 200f, 0.7f, 1.2f); //获取生物体 到理想抓取位置 直线距离上的Tile List <IntVector2> intVecLst = PhysicsUtils.RayTracedTilesArray(this.FloatBase, idealGrabDir); bool isFind = false; //遍历Tile for (int i = 0; i < intVecLst.Count - 1; ++i) { //如果是Solid地形,考虑抓取打分 if (this.room.GetTile(intVecLst[i + 1]).Solid) { this.ConsiderGrabPos(Utils.RestrictInRect(idealGrabDir, this.room.TileRect(intVecLst[i]).Shrink(1f)), this.idealGrabPos); isFind = true; break; } //垂直或水平竖杆 if (this.room.GetTile(intVecLst[i]).horizontalBeam || this.room.GetTile(intVecLst[i]).verticalBeam) { this.ConsiderGrabPos(this.room.MiddleOfTile(intVecLst[i]), this.idealGrabPos); isFind = true; } } //设置 是否发现抓取位置 计时 if (isFind) { this.foundNoGrabPos = 0; } else { ++this.foundNoGrabPos; } bool flag2 = this.secondaryGrabBackTrackCounter <200 && this.SecondaryGrabPosScore(this.secondaryGrabPos)> 0.0; for (int index = 0; index < this.tChunks.Length; ++index) { if (this.backtrackFrom == -1 || this.backtrackFrom > index) { //粘附在地形上 this.StickToTerrain(this.tChunks[index]); //如果存在抓取目标点 if (this.GrabDest.HasValue) { //如果不在抓取目标点 && Chunk距离目标点距离小于 20: 抓取目标点=true if (!this.atGrabDest && Utils.DistLess(this.tChunks[index].pos, this.floatGrabDest.Value, 20f)) { this.atGrabDest = true; } //修改Chunk的速度 if (this.tChunks[index].currentSegment <= this.grabPath.Count || !flag2) { this.tChunks[index].vel += Vector2.ClampMagnitude(this.floatGrabDest.Value - this.tChunks[index].pos, 20f) / 20f * 1.2f; } else if (index > 1 && this.segments.Count > this.grabPath.Count && flag2) { float ratio = Mathf.InverseLerp(grabPath.Count, segments.Count, tChunks[index].currentSegment); Vector2 dir = Utils.DirVec(this.tChunks[index - 2].pos, this.tChunks[index].pos) * (1f - ratio) * 0.6f + Utils.DirVec(this.tChunks[index].pos, this.room.MiddleOfTile(this.GrabDest.Value)) * Mathf.Pow(1f - ratio, 4f) * 2f + Utils.DirVec(this.tChunks[index].pos, this.room.MiddleOfTile(this.secondaryGrabPos)) * Mathf.Pow(ratio, 4f) * 2f + Utils.DirVec(this.tChunks[index].pos, this.FloatBase) * Mathf.Sin(ratio * (float)Math.PI) * 0.3f; this.tChunks[index].vel += dir.normalized * 1.2f; if (index == this.tChunks.Length - 1) { this.tChunks[index].vel += Vector2.ClampMagnitude(this.room.MiddleOfTile(this.secondaryGrabPos) - this.tChunks[index].pos, 20f) / 20f * 4.2f; } } } } } //如果抓取目标点存在值 if (this.GrabDest.HasValue) { this.ConsiderSecondaryGrabPos(this.GrabDest.Value + new IntVector2(UnityEngine.Random.Range(-20, 21), UnityEngine.Random.Range(-20, 21))); } //如果没有抓取目标点 or 不在抓取目标点:执行更新抓取目标点 if (!this.GrabDest.HasValue || !this.atGrabDest) { this.UpdateClimbGrabPos(); } }