コード例 #1
0
ファイル: SkeletonState.cs プロジェクト: lukyhruska96/VRLife
        public Skeleton ToNetworkModel()
        {
            Skeleton s = new Skeleton();

            s.UserId        = UserId;
            s.BodyLocation  = BodyLocation.ToCoord();
            s.BodyRotation  = BodyRotation.ToCoord();
            s.Head          = Head.ToCoord();
            s.Neck          = Neck.ToCoord();
            s.Spine         = Spine.ToCoord();
            s.Hips          = Hips.ToCoord();
            s.LeftShoulder  = LeftShoulder.ToCoord();
            s.LeftArm       = LeftArm.ToCoord();
            s.LeftHand      = LeftHand.ToCoord();
            s.RightShoulder = RightShoulder.ToCoord();
            s.RightArm      = RightArm.ToCoord();
            s.RightHand     = RightHand.ToCoord();
            s.LeftKnee      = LeftKnee.ToCoord();
            s.LeftFoot      = LeftFoot.ToCoord();
            s.RightKnee     = RightKnee.ToCoord();
            s.RightFoot     = RightFoot.ToCoord();
            return(s);
        }
コード例 #2
0
ファイル: WalkAi.cs プロジェクト: Evangeder/NeuralNetworkTest
    void Update()
    {
        //if (transform.rotation.eulerAngles.z > 90 && transform.rotation.eulerAngles.z < 270) Kill();

        //if (transform.position.x < -0.2f)
        //{
        //    net.SetFitness(-999);
        //    net.SetTimeAlive(-999);
        //    Kill();
        //}

        if (dontReward)
        {
            return;
        }

        if (netInitalized && manager.Countdown > 0)
        {
            if (_shouldPunish < 0)
            {
                _shouldPunish = 0;
            }

            float[] inputs =
            {
                HeadTransform.rotation.z,
                LeftArmTransform.rotation.z,
                RightArmTransform.rotation.z,
                LeftLegTransform.rotation.z,
                LeftFootTransform.rotation.z,
                RightLegTransform.rotation.z,
                RightFootTransform.rotation.z,
                _shouldPunish > 0f ? 100f : 0f,
                transform.position.x,
                Chest.transform.rotation.z,
                Chest.velocity.x,
                Chest.velocity.y,
                LeftLeg.velocity.x,
                LeftLeg.velocity.y,
                LeftLeg.angularVelocity,
                LeftFoot.velocity.x,
                LeftFoot.velocity.y,
                LeftFoot.angularVelocity,
                RightLeg.velocity.x,
                RightLeg.velocity.y,
                RightLeg.angularVelocity,
                RightFoot.velocity.x,
                RightFoot.velocity.y,
                RightFoot.angularVelocity,
                Vector2.Distance(new Vector2(transform.position.x, 0), new Vector2(WoD.Pos, 0))
            };

            float[] neurons = net.FeedForward(inputs);

            //HeadTransform.Rotate(Vector3.forward         , neurons[(int)Neuron.Head]);
            //LeftArmTransform.Rotate(Vector3.forward      , neurons[(int)Neuron.LeftArm]);
            //RightArmTransform.Rotate(Vector3.forward     , neurons[(int)Neuron.RightArm]);
            //LeftLegTransform.Rotate(Vector3.forward      , neurons[(int)Neuron.LeftLeg]);
            //LeftFootTransform.Rotate(Vector3.forward     , neurons[(int)Neuron.LeftFoot]);
            //RightLegTransform.Rotate(Vector3.forward     , neurons[(int)Neuron.RightLeg]);
            //RightFootTransform.Rotate(Vector3.forward    , neurons[(int)Neuron.RightFoot]);
            //ChestTransform.Rotate(Vector3.forward        , neurons[(int)Neuron.Torso]);

            Head.AddTorque(neurons[(int)Neuron.Head] * 5f, ForceMode2D.Force);
            LeftArm.AddTorque(neurons[(int)Neuron.LeftArm] * 5f, ForceMode2D.Force);
            RightArm.AddTorque(neurons[(int)Neuron.RightArm] * 5f, ForceMode2D.Force);
            LeftLeg.AddTorque(neurons[(int)Neuron.LeftLeg] * 20f, ForceMode2D.Force);
            LeftFoot.AddTorque(neurons[(int)Neuron.LeftFoot] * 20f, ForceMode2D.Force);
            RightLeg.AddTorque(neurons[(int)Neuron.RightLeg] * 20f, ForceMode2D.Force);
            RightFoot.AddTorque(neurons[(int)Neuron.RightFoot] * 20f, ForceMode2D.Force);
            Chest.AddTorque(neurons[(int)Neuron.Torso] * 5f, ForceMode2D.Force);

            if (_shouldPunish > 0)
            {
                if (killTimerValue > 0)
                {
                    killTimerValue -= Time.deltaTime;
                }
                else
                {
                    Kill();
                }
            }
            else
            {
                net.SetFitness(transform.position.x * 2);
                killTimerValue = killTimer;
            }

            net.SetTimeAlive(timeAlive);
            currentScore = net.GetFitness();

            lastPosition = transform.position.x;

            if (WoD.Pos >= transform.position.x)
            {
                Kill();
            }
        }

        timeAlive += Time.deltaTime;
    }
コード例 #3
0
    /// <summary>
    /// Alternates stepping forward with either leg in order to "walk" properly
    /// </summary>
    void WalkCycle()
    {
        JointMotor2D rightMotor = RightLeg.motor;
        JointMotor2D leftMotor  = LeftLeg.motor;

        RightFoot.rotation = Quaternion.Euler(Vector2.down);
        LeftFoot.rotation  = Quaternion.Euler(Vector2.down);

        Rigidbody2D rightRb = RightFoot.GetComponent <Rigidbody2D>();
        Rigidbody2D leftRb  = LeftFoot.GetComponent <Rigidbody2D>();

        float moveInput;

        if (playerInt == 1)//added by kate (:
        {
            //will be -1, 1 or 0
            moveInput = Input.GetAxisRaw("P1Horizontal");

            if (Input.GetKey(KeyCode.D))
            {
                moveInput = 1;
            }
            else if (Input.GetKey(KeyCode.A))
            {
                moveInput = -1;
            }
        }
        else
        {
            moveInput = Input.GetAxisRaw("P2Horizontal");

            if (Input.GetKey(KeyCode.L))
            {
                moveInput = 1;
            }
            else if (Input.GetKey(KeyCode.J))
            {
                moveInput = -1;
            }
        }

        if (moveInput > 0)
        {
            if (!reverseStep)
            {
//                Debug.Log(footStartXRight - RightFoot.transform.localPosition.x);
                if (footStartXRight - RightFoot.transform.localPosition.x < DistanceFromStraight)
                {
                    leftMotor.motorSpeed = LegMotorSpeed;
                    LeftLeg.motor        = leftMotor;
                    LeftLeg.useMotor     = true;
                    RightLeg.useMotor    = false;

                    rightRb.velocity = new Vector2(Mathf.Lerp(rightRb.velocity.x, MoveSpeed * 4, 0.1f), rightRb.velocity.y);
                }
                else if (footStartXRight - RightFoot.transform.localPosition.x >= DistanceFromStraight)
                {
                    reverseStep = true;

                    rightMotor.motorSpeed = LegMotorSpeed;
                    RightLeg.motor        = rightMotor;
                    RightLeg.useMotor     = true;

                    LeftLeg.useMotor = false;
                }
            }
            else if (reverseStep)
            {
                if (footStartXLeft - LeftFoot.transform.localPosition.x < DistanceFromStraight)
                {
                    leftRb.velocity = new Vector2(Mathf.Lerp(leftRb.velocity.x, MoveSpeed * 4, 0.1f), leftRb.velocity.y);
                }
                else if (footStartXLeft - LeftFoot.transform.localPosition.x >= DistanceFromStraight)
                {
                    reverseStep = false;

                    leftMotor.motorSpeed = LegMotorSpeed;
                    LeftLeg.motor        = leftMotor;
                    LeftLeg.useMotor     = true;

                    RightLeg.useMotor = false;
                }
            }
        }
        else if (moveInput < 0)
        {
            if (reverseStep)
            {
//                Debug.Log(footStartXRight - RightFoot.transform.localPosition.x);
                if (footStartXRight - RightFoot.transform.localPosition.x > -DistanceFromStraight)
                {
                    rightRb.velocity = new Vector2(Mathf.Lerp(rightRb.velocity.x, -MoveSpeed * 4, 0.1f), rightRb.velocity.y);
                }
                else if (footStartXRight - RightFoot.transform.localPosition.x <= -DistanceFromStraight)
                {
                    reverseStep = false;

                    rightMotor.motorSpeed = -LegMotorSpeed;
                    RightLeg.motor        = rightMotor;
                    RightLeg.useMotor     = true;

                    LeftLeg.useMotor = false;
                }
            }
            else if (!reverseStep)
            {
//                Debug.Log(footStartXRight - LeftFoot.transform.localPosition.x);
                if (footStartXLeft - LeftFoot.transform.localPosition.x > -DistanceFromStraight)
                {
                    rightMotor.motorSpeed = -LegMotorSpeed;
                    RightLeg.motor        = rightMotor;
                    RightLeg.useMotor     = true;

                    LeftLeg.useMotor = false;

                    leftRb.velocity = new Vector2(Mathf.Lerp(leftRb.velocity.x, -MoveSpeed * 4, 0.1f), leftRb.velocity.y);
                }
                else if (footStartXLeft - LeftFoot.transform.localPosition.x <= -DistanceFromStraight)
                {
                    reverseStep = true;

                    leftMotor.motorSpeed = -LegMotorSpeed;
                    LeftLeg.motor        = leftMotor;
                    LeftLeg.useMotor     = true;
                    RightLeg.useMotor    = false;
                }
            }
        }
        else
        {
            RightLeg.useMotor = true;
            LeftLeg.useMotor  = true;

            rightMotor.motorSpeed = 0;
            RightLeg.motor        = rightMotor;
            leftMotor.motorSpeed  = 0;
            LeftLeg.motor         = leftMotor;
//            LeftLeg.useMotor = false;
            reverseStep = false;
        }
    }
コード例 #4
0
ファイル: DataTypes.cs プロジェクト: lukyhruska96/VRLife
 public void MergeFrom(Skeleton other)
 {
     if (other == null)
     {
         return;
     }
     if (other.UserId != 0UL)
     {
         UserId = other.UserId;
     }
     if (other.bodyLocation_ != null)
     {
         if (bodyLocation_ == null)
         {
             bodyLocation_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         BodyLocation.MergeFrom(other.BodyLocation);
     }
     if (other.bodyRotation_ != null)
     {
         if (bodyRotation_ == null)
         {
             bodyRotation_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         BodyRotation.MergeFrom(other.BodyRotation);
     }
     if (other.head_ != null)
     {
         if (head_ == null)
         {
             head_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         Head.MergeFrom(other.Head);
     }
     if (other.neck_ != null)
     {
         if (neck_ == null)
         {
             neck_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         Neck.MergeFrom(other.Neck);
     }
     if (other.spine_ != null)
     {
         if (spine_ == null)
         {
             spine_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         Spine.MergeFrom(other.Spine);
     }
     if (other.hips_ != null)
     {
         if (hips_ == null)
         {
             hips_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         Hips.MergeFrom(other.Hips);
     }
     if (other.leftShoulder_ != null)
     {
         if (leftShoulder_ == null)
         {
             leftShoulder_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         LeftShoulder.MergeFrom(other.LeftShoulder);
     }
     if (other.leftArm_ != null)
     {
         if (leftArm_ == null)
         {
             leftArm_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         LeftArm.MergeFrom(other.LeftArm);
     }
     if (other.leftHand_ != null)
     {
         if (leftHand_ == null)
         {
             leftHand_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         LeftHand.MergeFrom(other.LeftHand);
     }
     if (other.rightShoulder_ != null)
     {
         if (rightShoulder_ == null)
         {
             rightShoulder_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         RightShoulder.MergeFrom(other.RightShoulder);
     }
     if (other.rightArm_ != null)
     {
         if (rightArm_ == null)
         {
             rightArm_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         RightArm.MergeFrom(other.RightArm);
     }
     if (other.rightHand_ != null)
     {
         if (rightHand_ == null)
         {
             rightHand_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         RightHand.MergeFrom(other.RightHand);
     }
     if (other.leftKnee_ != null)
     {
         if (leftKnee_ == null)
         {
             leftKnee_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         LeftKnee.MergeFrom(other.LeftKnee);
     }
     if (other.leftFoot_ != null)
     {
         if (leftFoot_ == null)
         {
             leftFoot_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         LeftFoot.MergeFrom(other.LeftFoot);
     }
     if (other.rightKnee_ != null)
     {
         if (rightKnee_ == null)
         {
             rightKnee_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         RightKnee.MergeFrom(other.RightKnee);
     }
     if (other.rightFoot_ != null)
     {
         if (rightFoot_ == null)
         {
             rightFoot_ = new global::VrLifeShared.Networking.NetworkingModels.Coord();
         }
         RightFoot.MergeFrom(other.RightFoot);
     }
 }
コード例 #5
0
ファイル: DataTypes.cs プロジェクト: lukyhruska96/VRLife
        public override int GetHashCode()
        {
            int hash = 1;

            if (UserId != 0UL)
            {
                hash ^= UserId.GetHashCode();
            }
            if (bodyLocation_ != null)
            {
                hash ^= BodyLocation.GetHashCode();
            }
            if (bodyRotation_ != null)
            {
                hash ^= BodyRotation.GetHashCode();
            }
            if (head_ != null)
            {
                hash ^= Head.GetHashCode();
            }
            if (neck_ != null)
            {
                hash ^= Neck.GetHashCode();
            }
            if (spine_ != null)
            {
                hash ^= Spine.GetHashCode();
            }
            if (hips_ != null)
            {
                hash ^= Hips.GetHashCode();
            }
            if (leftShoulder_ != null)
            {
                hash ^= LeftShoulder.GetHashCode();
            }
            if (leftArm_ != null)
            {
                hash ^= LeftArm.GetHashCode();
            }
            if (leftHand_ != null)
            {
                hash ^= LeftHand.GetHashCode();
            }
            if (rightShoulder_ != null)
            {
                hash ^= RightShoulder.GetHashCode();
            }
            if (rightArm_ != null)
            {
                hash ^= RightArm.GetHashCode();
            }
            if (rightHand_ != null)
            {
                hash ^= RightHand.GetHashCode();
            }
            if (leftKnee_ != null)
            {
                hash ^= LeftKnee.GetHashCode();
            }
            if (leftFoot_ != null)
            {
                hash ^= LeftFoot.GetHashCode();
            }
            if (rightKnee_ != null)
            {
                hash ^= RightKnee.GetHashCode();
            }
            if (rightFoot_ != null)
            {
                hash ^= RightFoot.GetHashCode();
            }
            return(hash);
        }
コード例 #6
0
 public void setHero_LeftFoot(LeftFoot hero_LeftFoot)
 {
     this.hero_LeftFoot = hero_LeftFoot;
 }