//public static bool checkStandCatchingBall(FBActor actor) { // if (actor.world.ball.owner != null || actor.world.ball.willBeCatched) // { // return false; // } // if (actor.m_particle.velocity.squareLength > actor.m_configuration.scb_maxSpeed.square) // { // return false; // } // var ballSquareSpeed = actor.world.ball.particleVelocity.squareLength; // if (ballSquareSpeed == Fix64.Zero) // { // return false; // } // var s = actor.world.ball.particlePosition - actor.m_particle.position; // var b = s.squareLength - actor.m_configuration.scb_offset.square; // var c = FixVector2.dot(s, actor.world.ball.particleVelocity); // var sigma = c.square - ballSquareSpeed * b; // if (sigma < Fix64.Zero) // { // return false; // } // var t = -(c + Fix64.Sqrt(sigma)); // t /= ballSquareSpeed; // if (t < actor.m_configuration.scb_minTime || t > actor.m_configuration.scb_maxTime) { // return false; // } // var height = actor.world.ball.estimateHeight(t); // if (height > actor.m_configuration.scb_maxBallHeight) // { // return false; // } // var ballLocalTarget = actor.world.ball.particleVelocity * t; // actor.world.ball.willCatchBall(actor, actor.world.ball.particlePosition + ballLocalTarget, t); // actor.m_stateVector = (s + ballLocalTarget).normalized; // actor.m_stateValue = t; // actor.m_nextState = StandCatchingBall.instance; // return true; //} //public static bool checkChestCatchingBall(FBActor actor) { // if (actor.world.ball.owner != null || actor.world.ball.willBeCatched) { // return false; // } // if (actor.m_particle.velocity.squareLength > actor.m_configuration.ccb_maxSpeed.square) { // return false; // } // var ballSquareSpeed = actor.world.ball.particleVelocity.squareLength; // if (ballSquareSpeed == Fix64.Zero) { // return false; // } // var s = actor.world.ball.particlePosition - actor.m_particle.position; // var b = s.squareLength - actor.m_configuration.ccb_offset.square; // var c = FixVector2.dot(s, actor.world.ball.particleVelocity); // var sigma = c.square - ballSquareSpeed * b; // if (sigma < Fix64.Zero || (-c + Fix64.Sqrt(sigma)) <= Fix64.Zero) { // return false; // } // var ballSpeed = Fix64.Sqrt(ballSquareSpeed); // var d = s.length; // var t = (d - actor.m_configuration.ccb_offset2) / ballSpeed; // if (t < actor.m_configuration.ccb_minTime || t > actor.m_configuration.ccb_maxTime) // { // return false; // } // var h = actor.world.ball.estimateHeight(t); // if (h <= actor.m_configuration.scb_maxBallHeight || h > actor.m_configuration.ccb_maxBallHeight) { // return false; // } // actor.m_stateVector = s / d; // actor.m_stateValue = t; // actor.m_nextState = ChestCatchingBall.instance; // actor.world.ball.willCatchBall(actor, actor.m_particle.position + actor.m_stateVector * actor.m_configuration.ccb_offset2, t, actor.m_configuration.ccb_ballHeight); // return true; //} //public static bool checkHeadCatchingBall(FBActor actor) //{ // if (actor.world.ball.owner != null || actor.world.ball.willBeCatched) // { // return false; // } // if (actor.m_particle.velocity.squareLength > actor.m_configuration.hcb_maxSpeed.square) // { // return false; // } // var ballSquareSpeed = actor.world.ball.particleVelocity.squareLength; // if (ballSquareSpeed == Fix64.Zero) // { // return false; // } // var s = actor.world.ball.particlePosition - actor.m_particle.position; // var b = s.squareLength - actor.m_configuration.hcb_offset.square; // var c = FixVector2.dot(s, actor.world.ball.particleVelocity); // var sigma = c.square - ballSquareSpeed * b; // if (sigma < Fix64.Zero || (-c + Fix64.Sqrt(sigma)) <= Fix64.Zero) // { // return false; // } // var ballSpeed = Fix64.Sqrt(ballSquareSpeed); // var d = s.length; // var t = (d - actor.m_configuration.hcb_offset2) / ballSpeed; // if (t < actor.m_configuration.hcb_minTime || t > actor.m_configuration.hcb_maxTime) // { // return false; // } // var h = actor.world.ball.estimateHeight(t); // if (h <= actor.m_configuration.hcb_maxBallHeight || h > actor.m_configuration.hcb_maxBallHeight) // { // return false; // } // actor.m_stateVector = s / d; // actor.m_stateValue = t; // actor.m_nextState = HeadCatchingBall.instance; // actor.world.ball.willCatchBall(actor, actor.m_particle.position + actor.m_stateVector * actor.m_configuration.hcb_offset2, t, actor.m_configuration.hcb_ballHeight); // return true; //} public override void enter(FBActor actor) { //jlx 2017.03.27-log: 修复:铲球、射门结束动作、传球结束动作之后,状态机没有正确流转下去 //actor.m_movingDirty = true; //actor._updateMovingState(); actor.updateMovingState(); }
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)); }
public override void update(FBActor actor, Fix64 deltaTime) { if (checkCatchingBall(actor)) { return; } actor.updateMovingState(); // 如果不移动,则减速 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; } var moveDirection = actor.m_moveDirection; var tween = !processCatchBallHelper(actor, ref moveDirection); // 如果移动方向满足转身条件 var acos = FixVector2.dot(actor.m_direction, moveDirection); if (acos <= actor.m_configuration.m2_minAngleCos) { Fix64[] minSpeedAndWaitTime = null; if (actor.world.ball.owner == actor) { minSpeedAndWaitTime = actor.m_configuration.m2_minSpeedAndWaitTime_ball; actor.m_stateSubState = 1; } else { minSpeedAndWaitTime = actor.m_configuration.m2_minSpeedAndWaitTime; actor.m_stateSubState = 0; } // 根据当前速度查询停留时间 var speed = actor.m_particle.velocity.length; for (int i = 0; i < minSpeedAndWaitTime.Length; i += 2) { if (speed > minSpeedAndWaitTime[i]) { // 切换至转身状态 actor.m_direction = -actor.m_direction; actor.ignoreDirectionSample = true; actor.m_particle.velocity = FixVector2.kZero; //actor.m_moving = false; //actor.m_movingDirty = true; actor.m_stateDataIndex = i; actor.m_nextState = (actor.m_stateSubState == 0 ? TurnBack.instance : TurnBackWithBall.instance); return; } } } // 正常移动 actor.m_particle.dampingAcceleration = Fix64.Zero; if (actor.world.ball.owner != actor) { actor.m_particle.maxSpeed = actor.m_configuration.m1_maxSpeed; Fix64 angluarSpeed = actor.AIing ? actor.m_configuration.m1_angularSpeed_ai : actor.m_configuration.m1_angularSpeed; processRotation(actor, moveDirection, tween, deltaTime * angluarSpeed); actor.m_particle.addForce(actor.m_direction * (actor.m_configuration.m1_moveForce * actor.m_movePower)); } else { actor.m_particle.maxSpeed = actor.m_configuration.m1_maxSpeed_ball; Fix64 angluarSpeed = actor.AIing ? actor.m_configuration.m1_angluarSpeed_ball_ai : actor.m_configuration.m1_angluarSpeed_ball; processRotation(actor, moveDirection, tween, deltaTime * angluarSpeed); actor.m_particle.addForce(actor.m_direction * (actor.m_configuration.m1_moveForce_ball * actor.m_movePower)); } //actor.m_particle.maxSpeed = actor.m_configuration.m1_maxSpeed; //FixVector2 force = actor.m_moveDirection * (actor.m_movePower * actor.m_configuration.m1_moveForce); //FixVector2 normalVelocity = actor.m_particle.velocity - actor.m_moveDirection * FixVector2.dot(actor.m_particle.velocity, actor.m_moveDirection); //Fix64 normalSpeed = normalVelocity.length; //if (normalSpeed > World.kEpsilon) //{ // var acc = normalSpeed / deltaTime; // if (acc > actor.m_configuration.m1_normalDampingAcceleration) // { // acc = actor.m_configuration.m1_normalDampingAcceleration; // } // force -= normalVelocity * (acc * actor.m_particle.mass / normalSpeed); //} //actor.m_particle.addForce(force); }
public override void enter(FBActor actor) { actor.m_RunTimeMovementState = instance; actor.updateMovingState(); }
public override void enter(FBActor actor) { actor.updateMovingState(); actor.m_timer = actor.m_configuration.moveStateWaitingTime; }