//检测源和目标之间是否被阻挡 bool checkBlocked(FBActor src, FBActor target) { FixVector2 a = (target.getPosition() - src.getPosition()).normalized; for (int i = 0; i < m_actors.Count; i++) { var actor = m_actors[i]; if (actor == src || actor == target) { continue; } FixVector2 c = actor.getPosition() - src.getPosition(); Fix64 dotData = FixVector2.dot(c, a); if (dotData <= Fix64.Zero) { continue; } Fix64 d = c.squareLength - Fix64.FastAbs(dotData * dotData); if (d < ball.configuration.radius * ball.configuration.radius) { return(true); } } return(false); }
public void doSliding(FBActor actor) { FBActor controlBallActor = null; List <FBActor> temp = new List <FBActor>(); for (int i = 0; i < m_actors.Count; ++i) { FBActor target = m_actors[i]; if (target == actor || target.ignoreCollision) { continue; } if (target.team == actor.team) { continue; } if (target.isDoorKeeper()) { continue; } FixVector2 relativePos = target.getPosition() - actor.getPosition(); if (relativePos.squareLength > actor.configuration.st_maxSlidingTargetDistance.square) { continue; } if (FixVector2.dot(actor.direction, relativePos.normalized) < Fix64.Cos(actor.configuration.st_maxSlidingTargetAngle)) { continue; } if (target.isCtrlBall()) { controlBallActor = target; break; } temp.Add(target); } if (controlBallActor != null) { actor.doSliding((controlBallActor.getPosition() - actor.getPosition()).normalized); } else if (temp.Count == 0) { actor.doSliding(actor.direction); } else { FixVector2 preferPoint = actor.getPosition(); temp.Sort(new FBActorTargetFindCompare(preferPoint)); actor.doSliding((temp[0].getPosition() - actor.getPosition()).normalized); } }
public override void enter(FBActor actor) { FixVector2 targetPosition = actor.world.ball.particlePosition + actor.world.ball.particleVelocity * actor.configuration.tcb_normalTime; //Debuger.Log("TigerCatchingBall currentBallPos:" // + (UnityEngine.Vector2)actor.world.ball.particlePosition // + " TargetPostion " + targetPosition // + " NeedTime:" + (float)actor.configuration.tcb_normalTime // + " actor.world.ball.particleVelocity:" + (UnityEngine.Vector2)actor.world.ball.particleVelocity); actor.world.ball.willCatchBall(actor, targetPosition, actor.configuration.tcb_normalTime); FixVector2 targetPositionVelocity = targetPosition - actor.getPosition(); Fix64 distance = targetPositionVelocity.length; targetPositionVelocity = targetPositionVelocity / distance; actor.m_stateVector = targetPositionVelocity * (distance / actor.configuration.tcb_normalTime); actor.particle.dampingAcceleration = Fix64.Zero; actor.direction = targetPositionVelocity; actor.m_stateSubState = (int)SubState.kBeforeCatching; actor.m_timer = actor.configuration.tcb_normalTime; actor.world.onActorTigerCatchingBallBegin(actor); }
//某个角色开始传球 //短传0,长传1 public void beginPassBall(FBActor actor, FixVector2 passBallDirection, int index) { //Debuger.Log("beginPassBall..........."); Fix64 maxR = m_ball.owner.configuration.passBallMaxR[index]; Fix64 minR = m_ball.owner.configuration.passBallMinR[index]; Fix64 angle = m_ball.owner.configuration.passBallFov[index]; Fix64 bestR = m_ball.owner.configuration.passBallBestR[index]; //没有键入方向,使用角色朝向 if (passBallDirection == FixVector2.kZero) { passBallDirection = actor.direction; } FBActor target = findTarget(m_ball.owner, passBallDirection, index, (int)m_ball.owner.team, m_ball.owner); if (target != null) { passBallDirection = target.getPosition() - m_ball.owner.getPosition(); passBallDirection = passBallDirection.normalized; } FixVector2 actorFaceDirection = getAjustedDirection(actor.direction, passBallDirection, actor.configuration.passBallAngleTorelance[index]); actor.doPassBall(index, actorFaceDirection); //保存传球对象 passBallType = index; passBallTarget = target; passBallDir = passBallDirection; }
Fix64 getDoorSide(FBActor actor, FixVector2 direction, out FixVector2 dest) { FixVector2 destDirection = direction; if (destDirection == FixVector2.kZero) { destDirection = actor.direction; } FixVector2 doorPosition = FixVector2.kZero; if (actor.team == FBTeam.kBlue) { doorPosition = new FixVector2(config.worldSize.x, Fix64.Zero); } else { doorPosition = new FixVector2(-config.worldSize.x, Fix64.Zero); } FixVector2 doorPointA = new FixVector2(doorPosition.x, config.doorHalfSize.y); FixVector2 doorPointB = new FixVector2(doorPosition.x, -config.doorHalfSize.y); FixVector2 diretionA = doorPointA - actor.getPosition(); diretionA.normalize(); FixVector2 diretionB = doorPointB - actor.getPosition(); diretionB.normalize(); Fix64 dotA = FixVector2.dot(destDirection, diretionA); Fix64 dotB = FixVector2.dot(destDirection, diretionB); if (dotA > dotB) { dest = diretionA; positiveDoorSide = Fix64.One; } else { positiveDoorSide = -Fix64.One; dest = diretionB; } return(positiveDoorSide); }
public void shootBallDirectly(FBActor actor, ShootType type) { var direction = (actor.getEnemyDoorPosition() - actor.getPosition()).normalized; FixVector2 doorPosition = FixVector2.kZero; FixVector2 destDirection = FixVector2.kZero; positiveDoorSide = getDoorSide(actor, direction, out destDirection); actor.shootBallDirectly(type, direction); }
public void onActorCreated(FBActor actor) { fbGame.generateRenderActionToTargetList <RAL.CreateActorAction>(FBGame.RenderActionListType.kLogicBefore, actor.id, actor.roleId, actor.team, actor.name, actor.getPosition().toVector2(), actor.isDoorKeeper(), actor.configuration.element, (float)actor.configuration.bodyHeight, actor.configuration.normalSpeed.ToFloatArray()); }
void onMainCharacterPassingBall(FBActor actor, BW31.SP2D.FixVector2 direction, int passType, FBActor target, List <FBActor> preferTargets) { showPassingBallTime = Time.fixedTime; minR = (float)actor.configuration.passBallMinR[passType]; maxR = (float)actor.configuration.passBallMaxR[passType]; bestR = (float)actor.configuration.passBallBestR[passType]; angle = (float)actor.configuration.passBallFov[passType] * Mathf.Rad2Deg; shootBallDirection = Quaternion.LookRotation(new Vector3((float)direction.x, 0.0f, (float)direction.y)); centerPos = new Vector3((float)actor.getPosition().x, 0.0f, (float)actor.getPosition().y); for (int i = 0; i < preferTargets.Count; ++i) { preferPoints.Add(new Vector3((float)preferTargets[i].getPosition().x, 0.0f, (float)preferTargets[i].getPosition().y)); } if (target != null) { targetPosition = new Vector3((float)target.getPosition().x, 0.0f, (float)target.getPosition().y); } else { targetPosition = Vector3.zero; } }
FixVector2 ajustActorBallCollideNormal(FixVector2 normal, FBActor actor, FixVector2 ballVelocity) { FixVector2 ajustedNormal = -normal; FixVector2 actorBallDirection = (actor.getPosition() - actor.world.ball.getPosition()).normalized; if (actor.particle.velocity.length > Fix64.Zero && FixVector2.dot(actorBallDirection, actor.direction) > Fix64.Cos(actor.configuration.maxBallActorCollideAngle)) { ajustedNormal = actor.direction - ballVelocity.normalized; ajustedNormal = ajustedNormal.normalized; } return(ajustedNormal); }
void onDoorKeeperCatchingBallView(FBActor actor, BW31.SP2D.FixVector2 point, Fix64 height) { areaData = new List <float>(); showTime = Time.fixedTime; centerPosition = new Vector3((float)actor.getPosition().x, (float)actor.height, (float)actor.getPosition().y); direction = Quaternion.LookRotation(new Vector3((float)actor.direction.x, 0, (float)actor.direction.y)); for (int i = 0; i < actor.configuration.dkcb_edgeLimit.Length; ++i) { areaData.Add((float)actor.configuration.dkcb_edgeLimit[i]); } hitCenter.y = (float)height; hitCenter.x = (float)point.x; hitCenter.z = (float)point.y; }
bool checkSlowGetPassingBall(FBActor src, FBActor target, int idx) { FixVector2 passBallDirection = (target.getPosition() - src.getPosition()).normalized; Fix64 dotD = FixVector2.dot(passBallDirection, target.direction); if (target.particle.velocity.squareLength <= target.configuration.getPassingBallStandOrMovingSpeed[idx].square || dotD >= Fix64.Cos(target.configuration.getPassingBallStandOrMovingAngle[idx])) { //检测Target当前的状态是否可以慢速接球 return(true); } return(false); }
public override void enter(FBActor actor) { if (actor.m_stateInt != (int)BallDetachType_Attacked.None) { FixVector2 velocity = actor.direction * (actor.particle.velocity.length + actor.configuration.ballDetachSpeedAttacked[(int)actor.m_stateInt]); FixVector3 position = actor.getBallPosition((BallDetachType_Attacked)actor.m_stateInt); actor.world.ball.freeByAttacked(position, velocity, Fix64.Zero); actor.world.ball.setSampleType(FBBall.SampleType.TimeSlerp, actor.configuration.ballDetachSlerpTimeAttacked[actor.m_stateInt]); } FixVector2 dir = (actor.getPosition() - actor.m_stateActor.getPosition()).normalized; actor.m_stateVector = dir * actor.m_stateActor.configuration.bst1_initialSpeed; if (actor.configuration.st_beAttackedFaceBackoff == 1) { actor.direction = dir; } else { actor.direction = -dir; } actor.m_stateSubState = (int)SubState.kDampingToZero; actor.m_timer = actor.m_stateActor.configuration.bst1_dampingToZeroTime; //持球队员被攻击 if (actor.m_stateInt != (int)BallDetachType_Attacked.None) { actor.world.fbGame.lerpToTimeScale( ConstTable.ActorAttackedSlowPlaySpeed, ConstTable.ActorAttackedSlowPlayTime, ConstTable.ActorAttackedResetTime, () => { actor.world.onBeginHit(actor.m_stateActor.id, actor.id); }, () => { actor.world.onEndHit(); }, () => { actor.world.onHitCompleted(); } ); } actor.world.onBeSlidDropBallBegin(actor, true); }
public override void update(FBActor actor, Fix64 deltaTime) { if (Movement.checkCatchingBall(actor)) { return; } actor.updateMovingState(); if (actor.m_stateActor == null && actor.m_stateBall == null) { actor.m_RunTimeMovementState = null; actor.setToMovementState(); return; } FixVector2 targetPosition = actor.m_stateActor != null?actor.m_stateActor.getPosition() : actor.m_stateBall.getPosition(); //处理旋转 var moveDirection = targetPosition - actor.getPosition(); moveDirection.normalize(); processRotation(actor, moveDirection, deltaTime * actor.m_configuration.m1_angularSpeed); // 如果不移动,则减速 if (actor.m_movePower == Fix64.Zero) { actor.m_particle.dampingAcceleration = actor.world.ball.owner != actor ? actor.m_configuration.m1_stopDampingAcceleration : actor.m_configuration.m1_stopDampingAcceleration_ball; return; } //处理位移 actor.m_particle.dampingAcceleration = Fix64.Zero; actor.defendMoveDirection = actor.getMoveDirection(); actor.m_particle.maxSpeed = actor.m_configuration.dm1_maxSpeed[(int)actor.defendMoveDirection - 1]; actor.m_particle.addForce(actor.moveDirection * (actor.m_configuration.m1_moveForce * actor.m_movePower)); }
/// <summary> /// AI在知道目标点的时候传球 /// </summary> /// <param name="actor"></param> /// <param name="passBallDirection"></param> /// <param name="index"></param> public bool passBallToTarget(FBActor target, int index) { if (target == null) { Debuger.LogError(" target is null"); return(false); } if (index < 0) { Debuger.LogError(" index < 0" + index); return(false); } var owner = m_ball.owner; if (owner == null) { Debuger.LogError(" owner is null"); return(false); } Fix64 maxR = owner.configuration.passBallMaxR[index]; Fix64 minR = owner.configuration.passBallMinR[index]; Fix64 angle = owner.configuration.passBallFov[index]; var passBallDirection = (target.getPosition() - owner.getPosition()).normalized; FixVector2 actorFaceDirection = getAjustedDirection(owner.direction, passBallDirection, owner.configuration.passBallAngleTorelance[index]); if (owner.doPassBall(index, actorFaceDirection)) { //保存传球对象 passBallType = index; passBallTarget = target; passBallDir = passBallDirection; return(true); } return(false); }
private FixVector2 getMoveTargetOffset(FBActor actor, out Fix64 heightOffset) { FixVector2 moveTaregetOffset = FixVector2.kZero; Fix64 moveHeight = Fix64.Zero; FixVector2 offset = actor.configuration.dkcb_cathingOffset[actor.m_stateDataIndex]; FixVector2 targetDirection = actor.m_stateVector - actor.getPosition(); Fix64 length = targetDirection.length; targetDirection = targetDirection / length; moveTaregetOffset = targetDirection * (length - offset.x); //Debuger.Log("getMoveTargetOffset configOffset:" + (UnityEngine.Vector2)offset // + " targetPosition:" + (UnityEngine.Vector2)actor.m_stateVector // + " actorPosition:" + (UnityEngine.Vector2)actor.getPosition()); heightOffset = actor.m_stateValue2 - offset.y; if (heightOffset <= Fix64.Zero) { heightOffset = Fix64.Zero; } return(moveTaregetOffset); }
void _beforeCatching(FBActor actor, Fix64 deltaTime) { actor.m_timer -= deltaTime; if (actor.m_timer <= Fix64.Zero) { Debuger.Log("beforeCatching end begin move"); actor.m_timer = actor.configuration.dkcb_animationCathingTime[actor.m_stateDataIndex]; actor.m_stateSubState = (int)SubState.kCatching; //移动球员位置到目标点 _getActorVelocity(actor, actor.m_timer, out actor.m_cathingBallStateMovingVelocity); actor.particle.dampingAcceleration = Fix64.Zero; //开始播放接球动画 actor.world.onDoorKeeperCatchingBall(actor, actor.m_stateDataIndex, FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero); return; } }
//检测是否可以停到球 public static bool checkCatchingBall(FBActor actor) { if (actor.world.ball.owner != null || actor.world.ball.willBeCatched) { return(false); } //球速度不能为0也不能太大 var ballSquareSpeed = actor.world.ball.particleVelocity.squareLength; if (ballSquareSpeed == Fix64.Zero || ballSquareSpeed > actor.configuration.scb_maxBallSpeed.square) { //Debuger.Log("Speed too big " + (float)ballSquareSpeed); return(false); } //球员速度不能太快 if (actor.particle.velocity.squareLength > actor.configuration.scb_maxActorSpeed.square) { //Debuger.Log("Actor too quick to get ball" + (float)actor.particle.velocity.squareLength); return(false); } //求出足球方向和检测半径是否有交点 Fix64 ballSpeedLength = actor.world.ball.particleVelocity.length; FixVector2 ballActor = actor.world.ball.getPosition() - actor.getPosition(); Fix64 dot = FixVector2.dot(-ballActor, actor.world.ball.particleVelocity / ballSpeedLength); //方向相反 if (dot <= Fix64.Zero) { //Debuger.Log("Negative Direction to getBall" + (float)ballActor.length); return(false); } Fix64 d2 = ballActor.squareLength - dot.square; //无交点 if (d2 > actor.configuration.scb_maxRadius) { //Debuger.Log("no intersect point" + (float)ballActor.length); return(false); } Fix64 b2 = actor.configuration.scb_maxRadius.square - d2; if (b2 <= Fix64.Zero) { //Debuger.Log("D1"); return(false); } Fix64 s = dot - Fix64.Sqrt(b2); if (s < Fix64.Zero) { //Debuger.Log("Ball in Range???" + (float)ballActor.length); return(false); } FixVector2 normalizedBallActor = ballActor.normalized; FixVector2 bIntersectPoint = actor.world.ball.getPosition() + s * actor.world.ball.particleVelocity.normalized; #if UNITY_EDITOR LogicEvent.fire("setIntersectPoint", bIntersectPoint); #endif Fix64 t = Fix64.Zero; Fix64 dampingAcceleration = Fix64.Zero; bool canReachPoint = actor.world.ball.estimate(bIntersectPoint, out t, out dampingAcceleration); if (!canReachPoint) { //Debuger.Log("Can not read Point"); return(false); } if (t >= actor.configuration.scb_maxCathingTime) { //Debuger.Log("t > scb_maxCathingTime distance:" + (float)ballActor.length); return(false); } //弹跳次数>1不处理 EstimateHeightInfo heightInfo = actor.world.ball.estimateHeight(t); if (heightInfo.landedTimes > 0) { //Debuger.Log("heightInfo.landedTimes > 0"); return(false); } //脚下停球 if (heightInfo.destHeight <= actor.configuration.scb_catchingHeightLimit[0]) { ////动画时间太短 //if (t < actor.configuration.scb_catchingAniTime[0]) //{ // Debuger.Log("t < actor.configuration.scb_catchingAniTime :t=" + (float)t); // return false; //} //Debuger.Log("StandCatchingBall begin"); FixVector2 faceTo = (bIntersectPoint - actor.getPosition()).normalized; FixVector2 target = actor.getPosition() + faceTo * actor.configuration.scb_catchingOffset[0]; actor.world.ball.willCatchFreeBall(actor, target, t, actor.configuration.scb_catchingOffsetH[0], Fix64.FastAbs(dampingAcceleration)); actor.m_stateVector = faceTo; actor.m_stateValue = t; actor.m_nextState = StandCatchingBall.instance; return(true); } for (int i = 1; i < actor.configuration.scb_catchingHeightLimit.Length; ++i) { if (heightInfo.destHeight > actor.configuration.scb_catchingHeightLimit[i - 1] && heightInfo.destHeight <= actor.configuration.scb_catchingHeightLimit[i] ) { //if (t < actor.configuration.scb_catchingAniTime[i]) //{ // Debuger.Log("Air Cathing ball can not procced moveTime:t" + (float)t + " aniTime:" + (float)actor.configuration.scb_catchingAniTime[i]); // return false; //} FixVector2 cPoint = actor.getPosition() + actor.configuration.scb_catchingOffset[i] * ballActor.normalized; actor.world.ball.willCatchFreeBall(actor, cPoint, t, actor.configuration.scb_catchingOffsetH[i], Fix64.FastAbs(dampingAcceleration)); actor.m_stateVector = normalizedBallActor; actor.m_stateValue = t; actor.m_stateDataIndex = i; actor.m_nextState = AirCatchingBall.instance; return(true); } } //Debuger.Log("can not get ball heightInfo.destHeight" + (float)heightInfo.destHeight); return(false); }
public override void enter(FBActor actor) { Fix64 animationTime = actor.configuration.dkcb_animationCathingTime[actor.m_stateDataIndex]; //足球飞行时间 Fix64 ballFlyTime = actor.m_stateValue; Debuger.Log("DoorKeeperCathingBall Begin zoneIndex:" + actor.m_stateDataIndex); //a\b区的情况 if (actor.m_stateDataIndex == 0 || actor.m_stateDataIndex == 1) { actor.m_stateInt = 1;//能拿到球 if (animationTime < ballFlyTime) { Debuger.Log("ab区 begin kBeforeCatching"); actor.m_stateSubState = (int)SubState.kBeforeCatching; actor.m_timer = ballFlyTime - animationTime; } else { Debuger.Log("ab区 begin kCatching"); //在BallFlyTime时间内移动到目标 _getActorVelocity(actor, ballFlyTime, out actor.m_cathingBallStateMovingVelocity); actor.particle.dampingAcceleration = Fix64.Zero; actor.m_stateSubState = (int)SubState.kCatching; actor.m_timer = ballFlyTime; //开始播放接球动画 actor.world.onDoorKeeperCatchingBall(actor, actor.m_stateDataIndex, FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero); } } else { Fix64 heightOffset = Fix64.Zero; FixVector2 moveTargetOffset = getMoveTargetOffset(actor, out heightOffset); Fix64 moveDistance = moveTargetOffset.length; Fix64 actorMoveTime = Fix64.Zero; if (actor.configuration.dkcb_cathingBallMovingVolocity[actor.m_stateDataIndex].x != Fix64.Zero) { actorMoveTime = moveDistance / actor.configuration.dkcb_cathingBallMovingVolocity[actor.m_stateDataIndex].x; } Fix64 actorMoveTimeVerticle = Fix64.Zero; if (actor.configuration.dkcb_cathingBallMovingVolocity[actor.m_stateDataIndex].y != Fix64.Zero) { actorMoveTimeVerticle = heightOffset / actor.configuration.dkcb_cathingBallMovingVolocity[actor.m_stateDataIndex].y; } Fix64 actorMoveTimeAjusted = actorMoveTime > actorMoveTimeVerticle ? actorMoveTime : actorMoveTimeVerticle; //不能拿到球 if (actorMoveTimeAjusted > ballFlyTime) { //直接移动 Fix64 verticleSpeed = _getActorVelocity(actor, actorMoveTimeAjusted, out actor.m_cathingBallStateMovingVelocity); actor.particle.dampingAcceleration = Fix64.Zero; actor.m_stateSubState = (int)SubState.kFlyCatching; //腾空时垂直方向上的速度 actor.m_cathingBallStateVerticleSpeed = verticleSpeed; actor.m_stateInt = 0;//不能拿到球 actor.m_timer = actorMoveTimeAjusted; //拿球动画 actor.world.onDoorKeeperCatchingBall( actor, actor.m_stateDataIndex, FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero); Debuger.Log(" can not get ball begin kFlyCatching"); } else { //动画时间比较长,直接开始做动画,并且开始移动,把球弹开 if (animationTime > ballFlyTime) { Fix64 verticleSpeed = _getActorVelocity(actor, ballFlyTime, out actor.m_cathingBallStateMovingVelocity); actor.particle.dampingAcceleration = Fix64.Zero; actor.m_stateSubState = (int)SubState.kFlyCatching; actor.m_cathingBallStateVerticleSpeed = verticleSpeed; actor.m_stateInt = 2;//把球弹开 actor.m_timer = ballFlyTime; //拿球动画 actor.world.onDoorKeeperCatchingBall( actor, actor.m_stateDataIndex, FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero); //Debuger.Log(" can colide ball begin kFlyCatching frameNumber: " + actor.world.world.frameCount); } else//动画时间比较短,接住球,先等待一段时间,然后播动画,做位移 { // Fix64 animationWaitTime = animationTime > actorMoveTimeAjusted ? animationTime : actorMoveTimeAjusted; actor.m_stateSubState = (int)SubState.kBeforeFlyCathing; actor.m_timer = ballFlyTime - animationWaitTime; actor.m_cathingBallStateAniWaitTime = animationWaitTime; Debuger.Log(" can get ball kBeforeFlyCathing"); } } } actor.world.onDoorKeeperCatchingBallReady(actor, actor.m_stateInt == 1); }
void doorKeeperCathingBall(FBActor shooter, FBActor actor) { //球的轨迹和守门员的交点 FixVector2 intersectPoint = FixVector2.kZero; Fix64 intersectHeight = Fix64.One; Fix64 ballFlyTime = Fix64.Zero; bool canHit = ball.estimateHit(actor.direction, -FixVector2.dot(actor.getPosition(), actor.direction), out ballFlyTime, out intersectPoint, out intersectHeight); if (!canHit) { Debuger.Log("Can not fly to doorkeeper"); return; } #if UNITY_EDITOR LogicEvent.fire("onDoorKeeperCatchingBallView", actor, intersectPoint, intersectHeight); #endif FixVector2 toward = intersectPoint - actor.getPosition(); Fix64 distance = toward.length; int cathingZoneIndex = -1; if (distance < actor.configuration.dkcb_edgeLimit[0]) { if (intersectHeight < actor.configuration.dkcb_edgeLimit[1]) { //a区 cathingZoneIndex = 0; } else if (intersectHeight < actor.configuration.dkcb_edgeLimit[2]) { //b区 cathingZoneIndex = 1; } else if (intersectHeight < actor.configuration.dkcb_edgeLimit[3]) { //c区 cathingZoneIndex = 2; } else { //H区,直接返回,不处理 cathingZoneIndex = -1; } } else if (distance < actor.configuration.dkcb_edgeLimit[6]) { if (intersectHeight < actor.configuration.dkcb_edgeLimit[4]) { //fe区 cathingZoneIndex = 4; } else if (intersectHeight < actor.configuration.dkcb_edgeLimit[5]) { //gd区 cathingZoneIndex = 3; } else { cathingZoneIndex = -1; } } else { //H区,直接返回,不处理 cathingZoneIndex = -1; } bool pretendCatchingBall = false; if ((cathingZoneIndex == 3 || cathingZoneIndex == 4)) { //修改获取球的区域 Fix64 rightDoorV = shooter.team == FBTeam.kBlue ? new Fix64(1) : new Fix64(-1); FixVector2 doorPosition = new FixVector2(config.worldSize.x * rightDoorV, Fix64.Zero); Fix64 s = (shooter.getPosition() - doorPosition).length; if (s > shooter.configuration.maxGoalDistance) { s = shooter.configuration.maxGoalDistance; } Fix64 shootRate = ConstTable.ShootBall_GoalRate[(int)shooter.shootingType] * ball.getEnergy().goalRate *((Fix64)1.0f - s / shooter.configuration.maxGoalDistance); //失误计算 Fix64 randV = this.randomUnit; pretendCatchingBall = randV >= shootRate; Debuger.Log("ShootBall GoalRate:" + (float)shootRate + " random:" + (float)randV); if (pretendCatchingBall) { if (cathingZoneIndex == 3) { intersectHeight -= ConstTable.GoallKeeperPretendGetBallMissDistance; if (intersectHeight < actor.configuration.dkcb_edgeLimit[4]) { cathingZoneIndex = 4; } } if (cathingZoneIndex == 4) { intersectHeight += ConstTable.GoallKeeperPretendGetBallMissDistance; if (intersectHeight > actor.configuration.dkcb_edgeLimit[4]) { cathingZoneIndex = 3; } } } } if (cathingZoneIndex != -1) { actor.doCathingGoalBall(new FixVector2(intersectPoint.x, intersectPoint.y), intersectHeight, ballFlyTime, cathingZoneIndex, pretendCatchingBall); } }
void _beforeFlyCatching(FBActor actor, Fix64 deltaTime) { actor.m_timer -= deltaTime; if (actor.m_timer <= Fix64.Zero) { //Debuger.Log("_beforeFlyCatching end begin move frameNumber:" + actor.world.world.frameCount); actor.m_timer = actor.m_cathingBallStateAniWaitTime; if (actor.m_stateBool && (actor.m_stateDataIndex == 3 || actor.m_stateDataIndex == 4)) { actor.m_stateInt = 0;//接不到球 } else { actor.m_stateInt = 1;//接到球 } Fix64 verticleSpeed = _getActorVelocity(actor, actor.m_timer, out actor.m_cathingBallStateMovingVelocity); actor.particle.dampingAcceleration = Fix64.Zero; actor.m_stateSubState = (int)SubState.kFlyCatching; actor.m_cathingBallStateVerticleSpeed = verticleSpeed; //开始播放接球动画 actor.world.onDoorKeeperCatchingBall(actor, actor.m_stateDataIndex, FixVector2.cross(actor.direction, actor.m_stateVector - actor.getPosition()) < Fix64.Zero); return; } }
void passBallOut() { var owner = m_ball.owner; bool fly = passBallType == 1; BallDetachType bt = passBallType == 1 ? BallDetachType.LongPass : BallDetachType.ShortPass; FixVector3 ballStartPosition = owner.getBallPosition(bt); FixVector2 frontPosition = new FixVector2(ballStartPosition.x, ballStartPosition.z); FBActor target = passBallTarget; if (target == null) { //Debuger.Log("PassingBall no target"); Fix64 passSpeed = owner.configuration.passingBallSpeedWhenNoTarget[passBallType]; Fix64 verticleSpeed = owner.configuration.passingBallVerticleSpeedWhenNoTarget[passBallType]; m_ball.freeByKick(ballStartPosition, (FixVector2)passBallDir * passSpeed, verticleSpeed, true); } else { //长传 if (fly) { if (checkSlowGetPassingBall(owner, target, 1)) { FixVector3 targetBallP = target.getBallPosition(BallAttachType.Long_StandGetPassingBall); var targetBallPosition = new FixVector2(targetBallP.x, targetBallP.z); //Debuger.Log("Long PassingBall slow get begin"); FixVector2 distance = frontPosition - targetBallPosition; Fix64 s = distance.length; Fix64 t = calculateSlowShortPassBallTime(s); //m_ball.freeByLongPass(targetBallPosition, target.configuration.ccb_ballHeight, t); m_ball.freeByLongPass(ballStartPosition, targetBallPosition, targetBallP.y, t); target.doGetPassingBallWhenStand(t, distance / s); } else if (checkQuickGetPassingBall(owner, target, 1)) { FixVector3 targetBallP = target.getBallPosition(BallAttachType.Long_RuningGetPasssingBall); var targetBallPosition = new FixVector2(targetBallP.x, targetBallP.z); Debuger.Log("Long PassingBall quick get begin"); Fix64 t = ((target.getPosition() - frontPosition).length + ConstTable.GetLongPasingBall_K1[1]) * ConstTable.GetLongPasingBall_K2[1]; targetBallPosition = targetBallPosition + target.particle.velocity * t; m_ball.freeByLongPass(ballStartPosition, targetBallPosition, targetBallP.y, t); target.doGetPassingBallWhenMoving(t); } else { //Debuger.Log("Long PassingBall Failed"); } } else { if (checkSlowGetPassingBall(owner, target, 0)) { FixVector3 targetBallP = target.getBallPosition(BallAttachType.Long_StandGetPassingBall); var targetBallPosition = new FixVector2(targetBallP.x, targetBallP.z); //Debuger.Log("short PassingBall slow get begin"); FixVector2 distance = frontPosition - targetBallPosition; Fix64 s = distance.length; Fix64 t = calculateSlowShortPassBallTime(s); target.doGetPassingBallWhenStand(t, distance / s); Fix64 t1 = t * ConstTable.GetShortPasingBall_K4[0]; Fix64 t2 = t * (Fix64.One - ConstTable.GetShortPasingBall_K4[0]); m_ball.freeByNormalPass(ballStartPosition, targetBallPosition, t1, t2); } else if (checkQuickGetPassingBall(owner, target, 0)) { FixVector3 targetBallP = target.getBallPosition(BallAttachType.Long_StandGetPassingBall); var targetBallPosition = new FixVector2(targetBallP.x, targetBallP.z); //Debuger.Log("short PassingBall quitk get begin"); Fix64 t = ((target.getPosition() - frontPosition).length + ConstTable.GetShortPasingBall_K2[1]) * ConstTable.GetShortPasingBall_K3[1]; targetBallPosition = targetBallPosition + target.particle.velocity * t; Fix64 t1 = t * ConstTable.GetShortPasingBall_K4[1]; Fix64 t2 = t * (Fix64.One - ConstTable.GetShortPasingBall_K4[1]); target.doGetPassingBallWhenMoving(t1 + t2); m_ball.freeByNormalPass(ballStartPosition, targetBallPosition, t1, t2); } else { //Debuger.Log("short PassingBall Failed"); } } } m_ball.increaseEnergy(fly ? owner.configuration.longPassEnergy : owner.configuration.shortPassEnergy); onPassBallOut(owner, m_ball.get3DVelocity()); }
public FBActor findTarget(FBActor src, FixVector2 direction, int index, int teamMask, FBActor exclude) { Fix64 maxRadius = src.configuration.passBallMaxR[index]; Fix64 minRadius = src.configuration.passBallMinR[index]; Fix64 theta = src.configuration.passBallFov[index]; Fix64 bestRadius = m_ball.owner.configuration.passBallBestR[index]; if (theta <= Fix64.Zero) { return(null); } var cosTheta = Fix64.Cos(theta); List <FBActor> preferTargets = new List <FBActor>(); var actorCount = m_actors.Count; for (int i = 0; i < actorCount; i++) { var actor = m_actors[i]; if (actor == exclude || ((int)actor.team & teamMask) == 0) { continue; } var d = actor.particle.position - src.getPosition(); var len = d.length; if (len < minRadius || len > maxRadius) { continue; } var cos = Fix64.Zero; if (len == Fix64.Zero) { cos = Fix64.One; } else { cos = FixVector2.dot(d.normalized, direction); } if (cos < cosTheta) { continue; } preferTargets.Add(actor); } FixVector2 preferPoint = src.getPosition() + direction * bestRadius; preferTargets.Sort(new FBActorTargetFindCompare(preferPoint)); FBActor destTarget = null; for (int i = 0; i < preferTargets.Count; ++i) { if (checkBlocked(src, preferTargets[i])) { continue; } destTarget = preferTargets[i]; break; } #if UNITY_EDITOR LogicEvent.fire("onMainCharacterPassingBall", src, direction, index, destTarget, preferTargets); #endif return(destTarget); }