/* * 今の周期のサーボ指定角度を返す関数 * サーボの並びは * WAIST = 0, //腰(回転方向不明) * LEFT_HIP_YAW = 1, //左股間節ヨー方向回転 * RIGHT_HIP_YAW = 2, //右股間節ヨー方向回転 * LEFT_HIP_ROLL = 3, //左股関節ロール方向回転 * RIGHT_HIP_ROLL = 4, //右股関節ロール方向回転 * LEFT_HIP_PITCH = 5, //左股関節ピッチ方向回転 * RIGHT_HIP_PITCH = 6, //右股関節ピッチ方向回転 * LEFT_KNEE = 7, //左膝 * RIGHT_KNEE = 8, //右膝 * LEFT_ANKLE_PITCH = 9, //左足首ピッチ方向回転 * RIGHT_ANKLE_PITCH = 10, //右足首ピッチ方向回転 * LEFT_ANKLE_ROLL = 11, //左足首ロール方向回転 * RIGHT_ANKLE_ROLL = 12, //右足首ロール方向回転 */ public int[] GetLowerServoDests() { oldStatus = nextStatus; nextStatus = GetMotionState(); if (currentStatus == MotionStatus.STOP && oldStatus == MotionStatus.STOP && nextStatus != MotionStatus.STOP) { finishFlag = true; } Debug.WriteLine("vartex : {0} {1}", vertex.x, vertex.y); Debug.WriteLine("MotionStatus current posID next : {0} {1} {2}", currentStatus, positionID, nextStatus); /*if (!changeFlag && currentStatus != nextStatus) * { * changeFlag = true; * }*/ if (finishFlag == true) { finishFlag = false; changeFlag = false; frameCount = 0; currentStatus = nextStatus; } frameCount++; return(GetMotionDests(currentStatus)); }
public void CalculateVotes() { // do we have a quorum, exlcuding those who abstain? if (Votes.Count < Config.Quorum || Votes.Count - Votes.Abstain < Config.Quorum) { Status = MotionStatus.OutOfOrder; StatusText = "Quorum is not present."; return; } // ties are failures if (Votes.No >= Votes.Yes) { Status = MotionStatus.Failed; return; } if (this.RequiresSuperMajority) { if (Votes.Yes < Config.SuperMajorityOfQuorum) { Status = MotionStatus.Failed; return; } } Status = MotionStatus.Passed; return; }
// Use this for initialization void Start() { transform.rotation = transform.parent.rotation; currentMotion = MotionStatus.Idle; currentRotation = Vector3.zero; targetRotation = Vector3.zero; motionRotation = Vector3.zero; TiltTime = tiltTime; TurnTime = turnTime; turnOverflow = 0; tiltOverflow = 0; }
private int[] GetMotionDests(MotionStatus motionStatus) { int[] ret; switch (motionStatus) { case MotionStatus.STOP: ret = GetSTOPDests(); break; case MotionStatus.WALK_FORWARD: ret = GetWALK_FORWARDDests(); break; case MotionStatus.WALK_BACKWARD: ret = GetWALK_BACKWARDDests(); break; case MotionStatus.WALK_RIGHT: ret = GetWALK_RIGHTDests(); break; case MotionStatus.WALK_LEFT: ret = GetWALK_LEFTDests(); break; case MotionStatus.TURN_RIGHT: ret = GetTURN_RIGHTDests(); break; case MotionStatus.TURN_LEFT: ret = GetTURN_LEFTDests(); break; default: ret = GetSTOPDests(); break; } return(AddTrim(ret)); }
/*internal*/ public MotionManager(ref SerialPortManager sp) { //コンストラクタで必要そうなもの //とりあえず最初は止まってるでしょう currentStatus = MotionStatus.STOP; oldStatus = MotionStatus.STOP; nextStatus = MotionStatus.STOP; wiiBBFrameCount = 0; changeFlag = false; finishFlag = true; //sp.Open(); //Debug.WriteLine("spmyport={0}", sp.MyPort.IsOpen); spm = sp; frameCount = 0; positionID = 0; weight = 0; wm = new Wiimote(); //Wiimoteの接続 this.wm.Connect(); //イベント関数の登録 this.wm.WiimoteChanged += wm_WiimoteChanged; }
//20f(收到消息解析,同步影子玩家) public void PlacePos(Transform target, InputBuffer buffer) { //分析按键组合,按优先级屏蔽无效操作 float y = (buffer.W ? MOVE_SPEED : 0) + (buffer.S ? -MOVE_SPEED : 0); float z = (buffer.D ? MOVE_SPEED : 0) + (buffer.A ? -MOVE_SPEED : 0); //移动 Vector3 position = Vector3.zero; if (OnGround() && y == 0) { position = new Vector3(0, 0, z); } if (OnGround() && playerVelocity.y < 0) { playerVelocity.y = 0; playerVelocity.z = 0; } //跳跃 if (OnGround() && y > 0) { if (z == 0) { //原地跳跃 playerVelocity.y += Mathf.Sqrt(JUMP_HEIGHT * -3.0f * GRAVITY);//平方根 } else if (z > 0) { //向前跳跃 playerVelocity.y += Mathf.Sqrt(JUMP_HEIGHT * -3.0f * GRAVITY); playerVelocity.z += 0.4f; } else if (z < 0) { //向后跳跃 playerVelocity.y += Mathf.Sqrt(JUMP_HEIGHT * -3.0f * GRAVITY); playerVelocity.z -= 0.4f; } } //衰减 playerVelocity.y += GRAVITY; if (OnGround() == false) { //在空中 if (playerVelocity.z > 0) { playerVelocity.z -= 0.05f; } else if (playerVelocity.z < 0) { playerVelocity.z += 0.05f; } } position += playerVelocity; //移动到的位置 Vector3 pos = target.position + position; pos.y = Mathf.Clamp(pos.y, 0, pos.y); //PushBox计算 if (rival.transform.position.z > transform.position.z) { //自己在左,对手在右 direction = Direction.Right; child.localScale = POS_SIZE; child.rotation = new Quaternion(0, 0, 0, 0); if (z > 0 && OnGround() && y == 0) { status = MotionStatus.MoveForward; } else if (z < 0 && OnGround() && y == 0) { status = MotionStatus.MoveBackward; } else if (z == 0 && OnGround() && y == 0) { status = MotionStatus.Idle; } else if (!OnGround()) { // 向前跳碰撞 status = MotionStatus.Jump; } else { //Debug.Log($"h={h} && hash={animator.GetCurrentAnimatorStateInfo(0).shortNameHash}"); } distance = rival.transform.position.z - pos.z; if (distance < SCALE_Z) { if ((status == MotionStatus.MoveForward || status == MotionStatus.JumpForward) && z > 0) { Vector3 pos1 = new Vector3(0, 0, SCALE_Z - distance); Debug.Log(distance + ",右推: " + pos1); Push(pos1); } else if (status == MotionStatus.Idle && rival.OnGround()) { Vector3 pos1 = new Vector3(0, 0, SCALE_Z - distance); Push(pos1); } } } else if (rival.transform.position.z < transform.position.z) { //对手在左,自己在右 direction = Direction.Left; child.localScale = NEG_SIZE; child.rotation = new Quaternion(0, 1, 0, 0); if (z > 0 && OnGround() && y == 0) { status = MotionStatus.MoveBackward; } else if (z < 0 && OnGround() && y == 0) { status = MotionStatus.MoveForward; } else if (z == 0 && OnGround() && y == 0) { status = MotionStatus.Idle; } else if (!OnGround()) { // 向前跳碰撞 status = MotionStatus.Jump; } else { //Debug.Log($"h={h} && hash={animator.GetCurrentAnimatorStateInfo(0).shortNameHash}"); } distance = pos.z - rival.transform.position.z; if (distance < SCALE_Z) { if ((status == MotionStatus.MoveForward || status == MotionStatus.JumpForward) && z < 0) { Vector3 pos1 = new Vector3(0, 0, distance - SCALE_Z); Debug.Log(distance + ",左推: " + pos1); Push(pos1);//移动中推动 } else if (status == MotionStatus.Idle && rival.OnGround()) { Vector3 pos1 = new Vector3(0, 0, distance - SCALE_Z); Push(pos1); } } } else { direction = Direction.Error; } InputRender render = new InputRender(); render.Tick = buffer.Tick; render.position = pos; buffers.Enqueue(render); }
// Update is called once per frame void Update() { // If moving backwards, speed up the turn time. Otherwise, set to standard TurnTime = currentMotion == MotionStatus.Backward ? 0.25f : 0.5f ; // Get current camera rotation and reset the target rotation's value. currentRotation.x -= currentRotation.x > 180 ? 360 : 0 ; currentRotation.y -= currentRotation.y > 180 ? 360 : 0 ; // Detect motion type currentMotion = Input.GetKey(KeyCode.W) ? MotionStatus.Forward : Input.GetKey(KeyCode.S) ? MotionStatus.Backward : MotionStatus.Idle ; currentMotion = Input.GetKey(KeyCode.A) ? currentMotion + 2 : Input.GetKey(KeyCode.D) ? currentMotion + 1 : currentMotion ; // Set target rotation targetRotation.x = movingIdle ? idleAngle : tiltAngle ; targetRotation.y = turningLeft ? turnAngle * -1 : turningRight ? turnAngle : 0 ; // Turn 180 degrees if moving backwards targetRotation.y += movingBackward ? 180 : 0 ; targetRotation.y -= targetRotation.y > 180 ? 360 : 0 ; // Calculate the rotation we want to apply to the camera. motionRotation.x = targetRotation.x > currentRotation.x? tiltSpeed * Time.deltaTime : targetRotation.x < currentRotation.x ? tiltSpeed * Time.deltaTime * -1 : 0 ; motionRotation.y = targetRotation.y > currentRotation.y ? turnSpeed * Time.deltaTime : targetRotation.y < currentRotation.y ? turnSpeed * Time.deltaTime * -1 : 0 ; motionRotation.z = -gameObject.transform.eulerAngles.z; // Prevent motionRotation from rotating beyond the desired tilt and turn angles. motionRotation.x = motionRotation.x > 0 && currentRotation.x + motionRotation.x > targetRotation.x ? Mathf.Abs(targetRotation.x - currentRotation.x) : motionRotation.x < 0 && currentRotation.x + motionRotation.x < targetRotation.x ? Mathf.Abs(targetRotation.x - currentRotation.x) * -1 : motionRotation.x ; motionRotation.y = motionRotation.y > 0 && currentRotation.y + motionRotation.y > targetRotation.y ? Mathf.Abs(targetRotation.y - currentRotation.y) : motionRotation.y < 0 && currentRotation.y + motionRotation.y < targetRotation.y ? Mathf.Abs(targetRotation.y - currentRotation.y) * -1 : motionRotation.y ; // Apply motionRotation to camera and currentRotation transform.Rotate(motionRotation); currentRotation += motionRotation; // Snap the rotation to the opposite angle of the parent's x rotation Vector3 tempRot = transform.rotation.eulerAngles; tempRot.x = currentRotation.x; tempRot.y = transform.parent.eulerAngles.y + currentRotation.y; transform.rotation = Quaternion.Euler(tempRot); }