private void Update() { if (Input.GetMouseButtonDown(1) && !Input.GetKey(KeyCode.LeftShift)) { _selector.SelectionByClick(); } else if (Input.GetMouseButtonDown(1) && Input.GetKey(KeyCode.LeftShift)) { _selector.MultipleSelectionByClick(); } if (Input.GetMouseButton(0)) { Ray ray = _selector.mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit) && hit.transform.CompareTag("Target")) { _targetMovement = hit.transform.GetComponent <TargetMovement>(); isTargetSpecific = true; } } if (Input.GetMouseButtonUp(0)) { if (isTargetSpecific) { _unitCommander.GoDestination(_targetMovement.GetDestinationPos(), _selector.GetSelectedUnits()); isTargetSpecific = false; } } _selector.CheckInput(); _selector.InteractWithUnits(); }
void FixedUpdate() { // episode termination criteria if (this.StepCount > 3000 | this.GetCumulativeReward() < -450) { TargetMovement t = Target.GetComponent(typeof(TargetMovement)) as TargetMovement; t.Respawn(); EndEpisode(); } }
public void NewGame(Dictionary <List <long>, Rectangle> inits, int moment = 0) { foreach (var pair in inits) { var i = random.Next(pair.Value.Left, pair.Value.Right); var j = random.Next(pair.Value.Top, pair.Value.Bottom); var value = pair.Key[random.Next(0, pair.Key.Count)]; TargetMovement.Appear(i, j, value, moment); } }
public void Clear(int moment) { for (var i = 0; i < TargetCore.Width; i++) { for (var j = 0; j < TargetCore.Height; j++) { if (TargetCore[i, j] != Core.None && TargetCore[i, j] != Core.BackGround) { TargetMovement.Disappear(i, j, moment); } } } }
/// <summary> /// 动画清空全区 /// </summary> /// <param name="moment">指示何时生效。</param> public void Clear(int moment) { for (var i = 0; i < TargetCore.Width; i++) { for (var j = 0; j < TargetCore.Height; j++) { if (TargetCore[i, j] != Core.NONE && TargetCore[i, j] != Core.BACK_GROUND) { TargetMovement.Disappear(i, j, moment); } } } }
public void InitializeTargetMovement() { var go = new GameObject(); mover = go.transform; mover.position = Vector3.zero; origin = Vector3.zero; rangeLimit = 2f; var speed = 1f; IUnityTime timeInformation = Substitute.For <IUnityTime>(); timeInformation.GetTime().Returns(1f); targetMovement = new TargetMovement(mover, origin, speed, rangeLimit, timeInformation); }
public void Generate(List <long> type, Rectangle area, int moment = 1) { var target = type[random.Next(0, type.Count)]; var p = new List <Point>(); for (var i = area.Left; i <= area.Right; i++) { for (var j = area.Top; j <= area.Bottom; j++) { if (TargetCore[i, j] == Core.None) { p.Add(new Point(i, j)); } } } if (p.Count == 0) { return; } var point = p[random.Next(0, p.Count)]; TargetMovement.Appear(point.X, point.Y, target, moment); }
private void DestroyTargets() { totalTargets = 0; GameObject[] targets = GameObject.FindGameObjectsWithTag("Target"); for (int i = 0; i < targets.Length; i++) { //Disable target movement TargetMovement targetMovement = targets[i].GetComponent<TargetMovement>(); targetMovement.enabled = false; // Enable the rigidbody on the target to allow it to fall. Rigidbody rigidyBody = targets[i].GetComponent<Rigidbody>(); rigidyBody.isKinematic = false; // Turn off collisions to prevent double hits. targets[i].GetComponent<Collider>().enabled = false; // Start to destroy this object. Destroy(targets[i], 1f); } }
void Update() { /*if (Input.GetKey (KeyCode.A) || Input.GetKey (KeyCode.LeftArrow)) { transform.Translate ((Vector3.left * speed * Time.deltaTime)); player.charState = CharState.Move; } else if (Input.GetKey (KeyCode.D) || Input.GetKey (KeyCode.RightArrow)) { transform.Translate ((Vector3.right * speed * Time.deltaTime)); player.charState = CharState.Move; } else { player.charState = CharState.Idle; }*/ if (AC.GlobalVariables.GetBooleanValue (42) || AC.GlobalVariables.GetBooleanValue (52)) { AC.KickStarter.playerMenus.DisableHotspotMenus (); if (Input.GetMouseButtonDown (0)) { if (isStanding && !waiting) { target = GameObject.FindObjectOfType<TargetMovement> (); targetRenderer = target.GetComponent<SpriteRenderer> (); Shoot (); waiting = true; StartCoroutine (Wait ()); } } if (Input.GetMouseButtonDown (1)) { isStanding = !isStanding; target = GameObject.FindObjectOfType<TargetMovement> (); targetRenderer = target.GetComponent<SpriteRenderer> (); if (isStanding) { //target.GetComponent<Animator> ().SetInteger ("param", Random.Range (0, 3)); //target.GetComponent<Animator> ().SetInteger ("param", 1); this.renderer.sprite = stand; //target.transform.position = enemy.transform.position; targetRenderer.enabled = true; } else { this.renderer.sprite = crouch; targetRenderer.enabled = false; } } } else { TargetMovement t = FindObjectOfType<TargetMovement> (); if (t != null) { Destroy (t); } } }
protected Core Move(int x_move, int y_move, int x_start, int y_start, int step_x_move, int step_y_move) { // 初始化 var answer = new Core(TargetCore); var record = new Core(TargetCore.GameSize); if (x_start < 0) { x_start += answer.Width; } if (y_start < 0) { y_start += answer.Height; } var during_step_x_move = -x_move; var during_step_y_move = -y_move; var x = x_start; var y = y_start; // 逐行/逐列处理 while (answer[x_start, y_start] != Core.OutOfRange) { x = x_start; y = y_start; while (answer[x, y] != Core.OutOfRange) { if (answer[x, y] != Core.None && answer[x, y] != Core.BackGround) { var now_number = answer[x, y]; // 取目标单元移动位置 var to = answer.LatestBlock(x, y, x_move, y_move); var to_number = answer[to.X, to.Y]; if (to_number == now_number) { // 合并 answer.Execute(TargetMovement.Move(x, y, to.X, to.Y)); answer.Execute(TargetMovement.Appear(to.X, to.Y, 2 * to_number, 1)); TargetCore.ToAddScore += Math.Abs(to_number * 2); record[to.X, to.Y] = answer[to.X, to.Y]; // 记录 answer[to.X, to.Y] = Core.BackGround; // 此位置已行动 } else if (to_number + now_number == 0) { // 湮灭 answer.Execute(TargetMovement.Move(x, y, to.X, to.Y)); answer.Execute(TargetMovement.Disappear(to.X, to.Y, 1)); TargetCore.ToAddScore += Math.Abs(to_number * 4); record[to.X, to.Y] = Core.WillDelete; // 记录 answer[to.X, to.Y] = Core.BackGround; // 此位置已行动 } else { // 反方向检查 var predict = answer.LatestBlock(x, y, -x_move, -y_move); var predict_number = answer[predict.X, predict.Y]; // 如果反方向上已经存在了一个负值,那么停止 if (predict_number + now_number == 0) { goto while_out; } // 移动 to.Offset(-x_move, -y_move); answer.Execute(TargetMovement.Move(x, y, to.X, to.Y)); } } while_out: x += during_step_x_move; y += during_step_y_move; } x_start += step_x_move; y_start += step_y_move; } return(answer.AddFrom(record)); }
void UpdateSwimming() { IgnorePlatforms = true; Vector2 footPos, handPos; float surfaceLimiter = 1.0f; Limb head = GetLimb(LimbType.Head); Limb torso = GetLimb(LimbType.Torso); if (currentHull != null && (currentHull.Rect.Y - currentHull.Surface > 50.0f)) { surfaceLimiter = (ConvertUnits.ToDisplayUnits(Collider.SimPosition.Y + 0.4f) - surfaceY); surfaceLimiter = Math.Max(1.0f, surfaceLimiter); if (surfaceLimiter > 50.0f) { return; } } Limb leftHand = GetLimb(LimbType.LeftHand); Limb rightHand = GetLimb(LimbType.RightHand); Limb leftFoot = GetLimb(LimbType.LeftFoot); Limb rightFoot = GetLimb(LimbType.RightFoot); float rotation = MathHelper.WrapAngle(Collider.Rotation); rotation = MathHelper.ToDegrees(rotation); if (rotation < 0.0f) { rotation += 360; } if (!character.IsRemotePlayer && !aiming && Anim != Animation.UsingConstruction) { if (rotation > 20 && rotation < 170) { TargetDir = Direction.Left; } else if (rotation > 190 && rotation < 340) { TargetDir = Direction.Right; } } float targetSpeed = TargetMovement.Length(); if (targetSpeed > 0.1f) { if (!aiming) { float newRotation = MathUtils.VectorToAngle(TargetMovement) - MathHelper.PiOver2; Collider.SmoothRotate(newRotation, 5.0f); //torso.body.SmoothRotate(newRotation); } } else { if (aiming) { Vector2 mousePos = ConvertUnits.ToSimUnits(character.CursorPosition); Vector2 diff = (mousePos - torso.SimPosition) * Dir; TargetMovement = new Vector2(0.0f, -0.1f); float newRotation = MathUtils.VectorToAngle(diff); Collider.SmoothRotate(newRotation, 5.0f); } } torso.body.SmoothRotate(Collider.Rotation); torso.body.MoveToPos(Collider.SimPosition + new Vector2((float)Math.Sin(-Collider.Rotation), (float)Math.Cos(-Collider.Rotation)) * 0.4f, 5.0f); if (TargetMovement == Vector2.Zero) { return; } movement = MathUtils.SmoothStep(movement, TargetMovement, 0.3f); //dont try to move upwards if head is already out of water if (surfaceLimiter > 1.0f && TargetMovement.Y > 0.0f) { if (TargetMovement.X == 0.0f) { //pull head above water head.body.SmoothRotate(0.0f, 5.0f); walkPos += 0.05f; } else { TargetMovement = new Vector2( (float)Math.Sqrt(targetSpeed * targetSpeed - TargetMovement.Y * TargetMovement.Y) * Math.Sign(TargetMovement.X), Math.Max(TargetMovement.Y, TargetMovement.Y * 0.2f)); //turn head above the water head.body.ApplyTorque(Dir); } movement.Y = movement.Y - (surfaceLimiter - 1.0f) * 0.01f; } if (!character.IsRemotePlayer || GameMain.Server != null) { Collider.LinearVelocity = Vector2.Lerp(Collider.LinearVelocity, movement * swimSpeed, movementLerp); } walkPos += movement.Length() * 0.2f; footPos = Collider.SimPosition - new Vector2((float)Math.Sin(-Collider.Rotation), (float)Math.Cos(-Collider.Rotation)) * 0.4f; for (int i = -1; i < 2; i += 2) { var thigh = i == -1 ? GetLimb(LimbType.LeftThigh) : GetLimb(LimbType.RightThigh); var leg = i == -1 ? GetLimb(LimbType.LeftLeg) : GetLimb(LimbType.RightLeg); float thighDiff = Math.Abs(MathUtils.GetShortestAngle(torso.Rotation, thigh.Rotation)); if (thighDiff > MathHelper.PiOver2) { //thigh bent too close to the torso -> force the leg to extend float thighTorque = thighDiff * thigh.Mass * Math.Sign(torso.Rotation - thigh.Rotation) * 10.0f; thigh.body.ApplyTorque(thighTorque); leg.body.ApplyTorque(thighTorque); } else { thigh.body.SmoothRotate(torso.Rotation + (float)Math.Sin(walkPos) * i * 0.3f, 2.0f); } } Vector2 transformedFootPos = new Vector2((float)Math.Sin(walkPos) * 0.5f, 0.0f); transformedFootPos = Vector2.Transform( transformedFootPos, Matrix.CreateRotationZ(Collider.Rotation)); MoveLimb(rightFoot, footPos - transformedFootPos, 1.0f); MoveLimb(leftFoot, footPos + transformedFootPos, 1.0f); handPos = (torso.SimPosition + head.SimPosition) / 2.0f; //at the surface, not moving sideways -> hands just float around if (!headInWater && TargetMovement.X == 0.0f && TargetMovement.Y > 0) { handPos.X = handPos.X + Dir * 0.6f; float wobbleAmount = 0.1f; if (!rightHand.Disabled) { MoveLimb(rightHand, new Vector2( handPos.X + (float)Math.Sin(walkPos / 1.5f) * wobbleAmount, handPos.Y + (float)Math.Sin(walkPos / 3.5f) * wobbleAmount - 0.25f), 1.5f); } if (!leftHand.Disabled) { MoveLimb(leftHand, new Vector2( handPos.X + (float)Math.Sin(walkPos / 2.0f) * wobbleAmount, handPos.Y + (float)Math.Sin(walkPos / 3.0f) * wobbleAmount - 0.25f), 1.5f); } return; } handPos += head.LinearVelocity * 0.1f; float handCyclePos = walkPos / 2.0f * -Dir; float handPosX = (float)Math.Cos(handCyclePos) * 0.4f; float handPosY = (float)Math.Sin(handCyclePos) * 1.0f; handPosY = MathHelper.Clamp(handPosY, -0.8f, 0.8f); Matrix rotationMatrix = Matrix.CreateRotationZ(torso.Rotation); if (!rightHand.Disabled) { Vector2 rightHandPos = new Vector2(-handPosX, -handPosY); rightHandPos.X = (Dir == 1.0f) ? Math.Max(0.3f, rightHandPos.X) : Math.Min(-0.3f, rightHandPos.X); rightHandPos = Vector2.Transform(rightHandPos, rotationMatrix); HandIK(rightHand, handPos + rightHandPos, 0.5f); } if (!leftHand.Disabled) { Vector2 leftHandPos = new Vector2(handPosX, handPosY); leftHandPos.X = (Dir == 1.0f) ? Math.Max(0.3f, leftHandPos.X) : Math.Min(-0.3f, leftHandPos.X); leftHandPos = Vector2.Transform(leftHandPos, rotationMatrix); HandIK(leftHand, handPos + leftHandPos, 0.5f); } }
void UpdateStanding() { Vector2 handPos; //if you're allergic to magic numbers, stop reading now Limb leftFoot = GetLimb(LimbType.LeftFoot); Limb rightFoot = GetLimb(LimbType.RightFoot); Limb head = GetLimb(LimbType.Head); Limb torso = GetLimb(LimbType.Torso); Limb waist = GetLimb(LimbType.Waist); Limb leftHand = GetLimb(LimbType.LeftHand); Limb rightHand = GetLimb(LimbType.RightHand); Limb leftLeg = GetLimb(LimbType.LeftLeg); Limb rightLeg = GetLimb(LimbType.RightLeg); float getUpSpeed = 0.3f; float walkCycleSpeed = movement.X * walkAnimSpeed; if (stairs != null) { TargetMovement = new Vector2(MathHelper.Clamp(TargetMovement.X, -1.5f, 1.5f), TargetMovement.Y); /*if ((TargetMovement.X > 0.0f && stairs.StairDirection == Direction.Right) || * TargetMovement.X < 0.0f && stairs.StairDirection == Direction.Left) * { * TargetMovement *= 1.7f; * //walkCycleSpeed *= 1.0f; * }*/ } Vector2 colliderPos = GetColliderBottom(); if (Math.Abs(TargetMovement.X) > 1.0f) { float slowdownAmount = 0.0f; if (currentHull != null) { //full slowdown (1.5f) when water is up to the torso surfaceY = ConvertUnits.ToSimUnits(currentHull.Surface); slowdownAmount = MathHelper.Clamp((surfaceY - colliderPos.Y) / torsoPosition, 0.0f, 1.0f) * 1.5f; } float maxSpeed = Math.Max(TargetMovement.Length() - slowdownAmount, 1.0f); TargetMovement = Vector2.Normalize(TargetMovement) * maxSpeed; } float walkPosX = (float)Math.Cos(walkPos); float walkPosY = (float)Math.Sin(walkPos); float runningModifier = (float)Math.Max(Math.Min(Math.Abs(TargetMovement.X), 3.0f) / 1.5f, 1.0); Vector2 stepSize = new Vector2( this.stepSize.X * walkPosX * runningModifier, this.stepSize.Y * walkPosY * runningModifier * runningModifier); if (Crouching) { stepSize *= 0.5f; } float footMid = colliderPos.X;// (leftFoot.SimPosition.X + rightFoot.SimPosition.X) / 2.0f; movement = overrideTargetMovement == Vector2.Zero ? MathUtils.SmoothStep(movement, TargetMovement * walkSpeed, movementLerp) : overrideTargetMovement; if (Math.Abs(movement.X) < 0.005f) { movement.X = 0.0f; } movement.Y = 0.0f; for (int i = 0; i < 2; i++) { Limb leg = GetLimb((i == 0) ? LimbType.LeftThigh : LimbType.RightThigh);// : leftLeg; float shortestAngle = leg.Rotation - torso.Rotation; if (Math.Abs(shortestAngle) < 2.5f) { continue; } if (Math.Abs(shortestAngle) > 5.0f) { TargetDir = TargetDir == Direction.Right ? Direction.Left : Direction.Right; } else { leg.body.ApplyTorque(shortestAngle * 10.0f); leg = GetLimb((i == 0) ? LimbType.LeftLeg : LimbType.RightLeg); leg.body.ApplyTorque(-shortestAngle * 10.0f); } } if (onGround && (!character.IsRemotePlayer || GameMain.Server != null)) { //move slower if collider isn't upright float rotationFactor = (float)Math.Abs(Math.Cos(Collider.Rotation)); Collider.LinearVelocity = new Vector2( movement.X * rotationFactor, Collider.LinearVelocity.Y > 0.0f ? Collider.LinearVelocity.Y * 0.5f : Collider.LinearVelocity.Y); } getUpSpeed = getUpSpeed * Math.Max(head.SimPosition.Y - colliderPos.Y, 0.5f); torso.pullJoint.Enabled = true; head.pullJoint.Enabled = true; waist.pullJoint.Enabled = true; float floorPos = GetFloorY(colliderPos + new Vector2(Math.Sign(movement.X) * 0.5f, 1.0f)); bool onSlope = floorPos > GetColliderBottom().Y + 0.05f; if (stairs != null || onSlope) { torso.pullJoint.WorldAnchorB = new Vector2( MathHelper.SmoothStep(torso.SimPosition.X, footMid + movement.X * 0.25f, getUpSpeed * 0.8f), MathHelper.SmoothStep(torso.SimPosition.Y, colliderPos.Y + TorsoPosition - Math.Abs(walkPosX * 0.05f), getUpSpeed * 2.0f)); head.pullJoint.WorldAnchorB = new Vector2( MathHelper.SmoothStep(head.SimPosition.X, footMid + movement.X * (Crouching ? 0.6f : 0.25f), getUpSpeed * 0.8f), MathHelper.SmoothStep(head.SimPosition.Y, colliderPos.Y + HeadPosition - Math.Abs(walkPosX * 0.05f), getUpSpeed * 2.0f)); waist.pullJoint.WorldAnchorB = waist.SimPosition;// +movement * 0.3f; } else { if (!onGround) { movement = Vector2.Zero; } torso.pullJoint.WorldAnchorB = MathUtils.SmoothStep(torso.SimPosition, new Vector2(footMid + movement.X * 0.2f, colliderPos.Y + TorsoPosition), getUpSpeed); head.pullJoint.WorldAnchorB = MathUtils.SmoothStep(head.SimPosition, new Vector2(footMid + movement.X * (Crouching && Math.Sign(movement.X) == Math.Sign(Dir) ? 0.6f : 0.2f), colliderPos.Y + HeadPosition), getUpSpeed * 1.2f); waist.pullJoint.WorldAnchorB = waist.SimPosition + movement * 0.06f; } if (!onGround) { Vector2 move = torso.pullJoint.WorldAnchorB - torso.SimPosition; foreach (Limb limb in Limbs) { MoveLimb(limb, limb.SimPosition + move, 15.0f, true); } return; } //moving horizontally if (TargetMovement.X != 0.0f) { //progress the walking animation walkPos -= (walkCycleSpeed / runningModifier) * 0.8f; for (int i = -1; i < 2; i += 2) { Limb foot = i == -1 ? leftFoot : rightFoot; Limb leg = i == -1 ? leftLeg : rightLeg; Vector2 footPos = stepSize * -i; if (stepSize.Y < 0.0f) { stepSize.Y = -0.15f; } if (onSlope && stairs == null) { footPos.Y *= 2.0f; } footPos.Y = Math.Min(waist.SimPosition.Y - colliderPos.Y - 0.4f, footPos.Y); MoveLimb(foot, footPos + colliderPos, 15.0f, true); foot.body.SmoothRotate(leg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20.0f * runningModifier); } if (runningModifier > 1.0f) { if (walkPosY > 0.0f) { GetLimb(LimbType.LeftThigh).body.ApplyTorque(-walkPosY * Dir * Math.Abs(movement.X) * thighTorque); } else { GetLimb(LimbType.RightThigh).body.ApplyTorque(walkPosY * Dir * Math.Abs(movement.X) * thighTorque); } } if (legTorque > 0.0f) { if (Math.Sign(walkPosX) != Math.Sign(movement.X)) { GetLimb(LimbType.LeftLeg).body.ApplyTorque(-walkPosY * Dir * Math.Abs(movement.X) * legTorque / runningModifier); } else { GetLimb(LimbType.RightLeg).body.ApplyTorque(walkPosY * Dir * Math.Abs(movement.X) * legTorque / runningModifier); } } //calculate the positions of hands handPos = torso.SimPosition; handPos.X = -walkPosX * 0.4f; float lowerY = -1.0f + (runningModifier - 1.0f) * 0.8f; handPos.Y = lowerY + (float)(Math.Abs(Math.Sin(walkPos - Math.PI * 1.5f) * 0.15 * runningModifier)); Vector2 posAddition = new Vector2(-movement.X * 0.015f * runningModifier, 0.0f); if (!rightHand.Disabled) { HandIK(rightHand, torso.SimPosition + posAddition + new Vector2( -handPos.X, (Math.Sign(walkPosX) == Math.Sign(Dir)) ? handPos.Y : lowerY), 0.7f * runningModifier); } if (!leftHand.Disabled) { HandIK(leftHand, torso.SimPosition + posAddition + new Vector2( handPos.X, (Math.Sign(walkPosX) == Math.Sign(-Dir)) ? handPos.Y : lowerY), 0.7f * runningModifier); } } else { //float movementFactor = (movement.X / 4.0f) * movement.X * Math.Sign(movement.X); for (int i = -1; i < 2; i += 2) { Vector2 footPos = colliderPos; if (Crouching) { footPos = new Vector2( waist.SimPosition.X + Math.Sign(stepSize.X * i) * Dir * 0.3f, colliderPos.Y - 0.1f); } else { footPos = new Vector2(GetCenterOfMass().X + stepSize.X * i * 0.2f, colliderPos.Y - 0.1f); } if (stairs == null) { footPos.Y = Math.Max(Math.Min(floorPos, footPos.Y + 0.5f), footPos.Y); } var foot = i == -1 ? rightFoot : leftFoot; MoveLimb(foot, footPos, Math.Abs(foot.SimPosition.X - footPos.X) * 100.0f, true); } leftFoot.body.SmoothRotate(Dir * MathHelper.PiOver2, 50.0f); rightFoot.body.SmoothRotate(Dir * MathHelper.PiOver2, 50.0f); if (!rightHand.Disabled) { rightHand.body.SmoothRotate(0.0f, 5.0f); var rightArm = GetLimb(LimbType.RightArm); rightArm.body.SmoothRotate(0.0f, 20.0f); } if (!leftHand.Disabled) { leftHand.body.SmoothRotate(0.0f, 5.0f); var leftArm = GetLimb(LimbType.LeftArm); leftArm.body.SmoothRotate(0.0f, 20.0f); } } }
void Start() { camera = FindObjectOfType <MapCamera> (); target = FindObjectOfType <TargetMovement> (); }
public override void UpdateAnim(float deltaTime) { if (Frozen) { return; } if (MainLimb == null) { return; } var mainLimb = MainLimb; levitatingCollider = !IsHanging; if (!character.CanMove) { levitatingCollider = false; Collider.FarseerBody.FixedRotation = false; if (GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient) { Collider.Enabled = false; Collider.LinearVelocity = mainLimb.LinearVelocity; Collider.SetTransformIgnoreContacts(mainLimb.SimPosition, mainLimb.Rotation); //reset pull joints to prevent the character from "hanging" mid-air if pull joints had been active when the character was still moving //(except when dragging, then we need the pull joints) if (!character.CanBeDragged || character.SelectedBy == null) { ResetPullJoints(); } } if (character.IsDead && deathAnimTimer < deathAnimDuration) { deathAnimTimer += deltaTime; UpdateDying(deltaTime); } else if (!InWater && !CanWalk && character.AllowInput) { //cannot walk but on dry land -> wiggle around UpdateDying(deltaTime); } return; } else { deathAnimTimer = 0.0f; } //re-enable collider if (!Collider.Enabled) { var lowestLimb = FindLowestLimb(); Collider.SetTransform(new Vector2( Collider.SimPosition.X, Math.Max(lowestLimb.SimPosition.Y + (Collider.radius + Collider.height / 2), Collider.SimPosition.Y)), 0.0f); Collider.Enabled = true; } ResetPullJoints(); if (strongestImpact > 0.0f) { character.Stun = MathHelper.Clamp(strongestImpact * 0.5f, character.Stun, 5.0f); strongestImpact = 0.0f; } if (aiming) { TargetMovement = TargetMovement.ClampLength(2); } if (inWater && !forceStanding) { Collider.FarseerBody.FixedRotation = false; UpdateSineAnim(deltaTime); } else if (RagdollParams.CanWalk && (currentHull != null || forceStanding)) { if (CurrentGroundedParams != null) { //rotate collider back upright float standAngle = CurrentGroundedParams.ColliderStandAngleInRadians * Dir; if (Math.Abs(MathUtils.GetShortestAngle(Collider.Rotation, standAngle)) > 0.001f) { Collider.AngularVelocity = MathUtils.GetShortestAngle(Collider.Rotation, standAngle) * 60.0f; Collider.FarseerBody.FixedRotation = false; } else { Collider.FarseerBody.FixedRotation = true; } } UpdateWalkAnim(deltaTime); } if (character.SelectedCharacter != null) { DragCharacter(character.SelectedCharacter, deltaTime); return; } if (character.AnimController.AnimationTestPose) { ApplyTestPose(); } //don't flip when simply physics is enabled if (SimplePhysicsEnabled) { return; } if (!character.IsRemotelyControlled && (character.AIController == null || character.AIController.CanFlip) && !aiming) { if (!inWater || (CurrentSwimParams != null && CurrentSwimParams.Mirror)) { if (targetMovement.X > 0.1f && targetMovement.X > Math.Abs(targetMovement.Y) * 0.2f) { TargetDir = Direction.Right; } else if (targetMovement.X < -0.1f && targetMovement.X < -Math.Abs(targetMovement.Y) * 0.2f) { TargetDir = Direction.Left; } } else { float rotation = MathHelper.WrapAngle(Collider.Rotation); rotation = MathHelper.ToDegrees(rotation); if (rotation < 0.0f) { rotation += 360; } if (rotation > 20 && rotation < 160) { TargetDir = Direction.Left; } else if (rotation > 200 && rotation < 340) { TargetDir = Direction.Right; } } } if (!CurrentFishAnimation.Flip) { return; } if (IsStuck) { return; } if (character.AIController != null && !character.AIController.CanFlip) { return; } flipCooldown -= deltaTime; if (TargetDir != Direction.None && TargetDir != dir) { flipTimer += deltaTime; // Speed reductions are not taken into account here. It's intentional: an ai character cannot flip if it's heavily paralyzed (for example). float requiredSpeed = CurrentAnimationParams.MovementSpeed / 2; if (CurrentHull != null) { // Enemy movement speeds are halved inside submarines requiredSpeed /= 2; } bool isMovingFastEnough = Math.Abs(MainLimb.LinearVelocity.X) > requiredSpeed; bool isTryingToMoveHorizontally = Math.Abs(TargetMovement.X) > Math.Abs(TargetMovement.Y); if ((flipTimer > CurrentFishAnimation.FlipDelay && flipCooldown <= 0.0f && ((isMovingFastEnough && isTryingToMoveHorizontally) || IsMovingBackwards)) || character.IsRemotePlayer) { Flip(); if (!inWater || (CurrentSwimParams != null && CurrentSwimParams.Mirror)) { Mirror(CurrentSwimParams != null ? CurrentSwimParams.MirrorLerp : true); } flipTimer = 0.0f; flipCooldown = CurrentFishAnimation.FlipCooldown; } } else { flipTimer = 0.0f; } wasAiming = aiming; aiming = false; wasAimingMelee = aimingMelee; aimingMelee = false; }
// Use this for initialization void Start() { anim = GetComponentInChildren <Animator> (); movementScript = GetComponent <TargetMovement> (); }