Esempio n. 1
0
 void FixedUpdate()
 {
     foreach (WheelJoint2D j in GetComponents <WheelJoint2D> ())
     {
         JointMotor2D m = j.motor;
         m.motorSpeed = max_speed * throttle * -1f;
         j.motor      = m;
     }
 }
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Hero")
     {
         JointMotor2D theMotor = pivotHingeJoint.motor;
         theMotor.motorSpeed   = 100f;
         pivotHingeJoint.motor = theMotor;
     }
 }
Esempio n. 3
0
    void setMotor(float speed_)
    {
        JointMotor2D motor = new JointMotor2D {
            motorSpeed = speed_, maxMotorTorque = wheelB.motor.maxMotorTorque
        };

        wheelB.motor = motor;
        wheelF.motor = motor;
    }
Esempio n. 4
0
    private void Start()
    {
        joint = gameObject.GetComponent <HingeJoint2D>();

        motor            = joint.motor;
        joint.useMotor   = false;
        motor.motorSpeed = 900f;
        joint.useMotor   = true;
    }
 private void CheckForKeyboardInputs()
 {
     if (zoneDetector.zoneEntered)
     {
         JointMotor2D theMotor = pivotHingeJoint.motor;
         theMotor.motorSpeed   = 100f;
         pivotHingeJoint.motor = theMotor;
     }
 }
Esempio n. 6
0
    /// <summary>
    /// Update physical car (transform, properties, scale of game objects) from variables.
    /// </summary>
    public void UpdateFromVariables()
    {
        // Apply values from dictionary
        LeftWheelRadius    = GenesToValues[GeneType.LeftWheelRadius];
        RightWheelRadius   = GenesToValues[GeneType.RightWheelRadius];
        LeftWheelPosition  = new Vector2(GenesToValues[GeneType.LeftWheelPosX], GenesToValues[GeneType.LeftWheelPosY]);
        RightWheelPosition = new Vector2(GenesToValues[GeneType.RightWheelPosX], GenesToValues[GeneType.RightWheelPosY]);
        Speed          = GenesToValues[GeneType.Speed];
        BaseDimensions = new Vector2(GenesToValues[GeneType.BaseDimensionsX], GenesToValues[GeneType.BaseDimensionsY]);

        // Reset transform
        BaseOfCar.transform.localPosition = Vector3.zero;
        BaseOfCar.transform.localRotation = Quaternion.Euler(Vector3.zero);

        // Apply values to base.
        //BaseDimensions.x *= 2f; // TO HELP FIX THE CAR JUST BEING WHEELS
        BaseOfCar.transform.localScale = new Vector3(BaseDimensions.x, BaseDimensions.y, 1f);

        Vector2 sizeOfBase = new Vector2(BaseOfCar.GetComponent <BoxCollider2D>().size.x *BaseOfCar.transform.localScale.x,
                                         BaseOfCar.GetComponent <BoxCollider2D>().size.y *BaseOfCar.transform.localScale.y);

        // Apply values to left wheel
        LeftWheel.transform.localScale = new Vector3(LeftWheelRadius, LeftWheelRadius, 1f);

        var leftWheelPos = new Vector2(
            Mathf.Clamp01(LeftWheelPosition.x) - 0.5f,
            Mathf.Clamp01(LeftWheelPosition.y) - 0.5f);

        leftWheelPos.x *= (sizeOfBase.x);
        leftWheelPos.y *= (sizeOfBase.y);


        LeftWheel.transform.localPosition = new Vector3(leftWheelPos.x, leftWheelPos.y, 1f);

        // Apply values to right wheel
        RightWheel.transform.localScale = new Vector3(RightWheelRadius, RightWheelRadius, 1f);

        var rightWheelPos = new Vector2(
            Mathf.Clamp01(RightWheelPosition.x) - 0.5f,
            Mathf.Clamp01(RightWheelPosition.y) - 0.5f);

        rightWheelPos.x *= (sizeOfBase.x);
        rightWheelPos.y *= (sizeOfBase.y);

        RightWheel.transform.localPosition = new Vector3(rightWheelPos.x, rightWheelPos.y, 1f);

        // Apply speed values to left and right wheels.
        var newMotor = new JointMotor2D {
            maxMotorTorque = 1000000f, motorSpeed = Speed
        };

        LeftWheel.GetComponent <HingeJoint2D>().useMotor = true;
        LeftWheel.GetComponent <HingeJoint2D>().motor    = newMotor;

        RightWheel.GetComponent <HingeJoint2D>().useMotor = true;
        RightWheel.GetComponent <HingeJoint2D>().motor    = newMotor;
    }
Esempio n. 7
0
    private void changeMotorDirection()
    {
        JointMotor2D motor = joint.motor;

        motor.motorSpeed = joint.motor.motorSpeed * -1;
        joint.motor      = motor;

        changingDirection = false;
    }
Esempio n. 8
0
    protected void SetAcceleration(int acceleration)
    {
        JointMotor2D motor = new JointMotor2D();

        motor.motorSpeed     = hj.motor.motorSpeed;
        motor.maxMotorTorque = acceleration;

        hj.motor = motor;
    }
Esempio n. 9
0
 private void Start()
 {
     _wheelJoints       = CarPrefab.GetComponents <WheelJoint2D>();
     _wheels            = _wheelJoints[0].motor;
     _angleTimer        = GetComponent <AngleTimer>();
     _audioSource       = GetComponent <AudioSource>();
     _audioSource.pitch = 0;
     _sfxSource         = SfxManagerObj.transform.Find("SoundFX").GetComponent <AudioSource>();
 }
Esempio n. 10
0
 private void SwingRight()
 {
     swordMotor                = swordSwing.motor;
     swordMotor.motorSpeed     = attackSpeed * 20;
     swordMotor.maxMotorTorque = attackPower;
     swordSwing.motor          = swordMotor;
     attackSpeed               = 0f;
     thrustPowerText.text      = attackSpeed.ToString();
 }
Esempio n. 11
0
    protected void SetSpeed(int speed)
    {
        JointMotor2D motor = new JointMotor2D();

        motor.motorSpeed     = speed;
        motor.maxMotorTorque = hj.motor.maxMotorTorque;

        hj.motor = motor;
    }
Esempio n. 12
0
 private void Thrust()
 {
     swordMotor                = swordThrust.motor;
     swordMotor.motorSpeed     = -attackSpeed;
     swordMotor.maxMotorTorque = attackPower;
     swordThrust.motor         = swordMotor;
     attackSpeed               = 0f;
     thrustPowerText.text      = attackSpeed.ToString();
 }
Esempio n. 13
0
 // Use this for initialization
 void Start()
 {
     rb2d2.GetComponent <Rigidbody2D>();
     hinge2D2.GetComponent <HingeJoint2D>();
     motorRef            = hinge2D2.motor;
     hinge2D2.useMotor   = true;
     motorRef.motorSpeed = -500;
     hinge2D2.motor      = motorRef;
 }
Esempio n. 14
0
    void rotate(float Speed)
    {
        joint2D.useMotor = true;
        JointMotor2D motor = joint2D.motor;

        motor.maxMotorTorque = maxForce;
        motor.motorSpeed     = Speed;
        joint2D.motor        = motor;
    }
Esempio n. 15
0
 // Use this for initialization
 void Start()
 {
     //set the center of mass of the car
     GetComponent <Rigidbody2D>().centerOfMass = centerOfMass.transform.localPosition;
     //get the wheeljoint components
     wheelJoints = gameObject.GetComponents <WheelJoint2D>();
     //get the reference to the motor of rear wheels joint
     motorBack = wheelJoints[0].motor;
 }
Esempio n. 16
0
 protected override void OnBuild()
 {
     rb.isKinematic             = false;
     jointMotor2D               = hingeJoint2D.motor;
     hingeJoint2D.connectedBody = groundTransform.GetComponent <Rigidbody2D>();
     //hingeJoint2D.connectedAnchor = transform.position + new Vector3(0.0f, hingeJoint2D.transform.localPosition.y, 0.0f);
     Wait();
     base.OnBuild();
 }
Esempio n. 17
0
 // Start is called before the first frame update
 void Start()
 {
     player     = new GameObject[2];
     player[0]  = GameObject.Find("MoMi");
     player[1]  = GameObject.Find("MoMu");
     hinge      = GetComponent <HingeJoint2D>();
     motorPower = new JointMotor2D();
     motorPower.maxMotorTorque = 10000;
 }
Esempio n. 18
0
        private void Update()
        {
            float        targetAngle = worldAngle ? this.targetAngle : _jointRigidbody.rotation - this.targetAngle;
            float        rotTarget   = Mathf.DeltaAngle(targetAngle, joint.connectedBody.rotation);
            JointMotor2D motor       = joint.motor;

            motor.motorSpeed = Mathf.Clamp(-rotTarget * speed, -maxSpeed, maxSpeed);
            joint.motor      = motor;
        }
Esempio n. 19
0
    // Use this for initialization
    void Start()
    {
        joint          = GetComponent <HingeJoint2D> ();
        joint.useMotor = false;
        JointMotor2D motor = joint.motor;

        motor.motorSpeed = motorSpeed;
        joint.motor      = motor;
    }
Esempio n. 20
0
        //specify motor
        public HingeJoint2D AddHingeJoint(JointMotor2D C_JM2D, Vector2 position)
        {
            HingeJoint2D C_HJ2D = gameObject.AddComponent <HingeJoint2D>();

            C_HJ2D.anchor   = transform.InverseTransformPoint(position);
            C_HJ2D.motor    = C_JM2D;
            C_HJ2D.useMotor = true;
            return(C_HJ2D);
        }
    public IEnumerator speedTime()
    {
        yield return(new WaitForSeconds(time));

        motor = new JointMotor2D {
            motorSpeed = speed, maxMotorTorque = wheelJoint.motor.maxMotorTorque
        };
        ChangeSpeed();
    }
Esempio n. 22
0
    private void FixedUpdate()
    {
        JointMotor2D motor = new JointMotor2D {
            motorSpeed = movement, maxMotorTorque = 10000
        };

        backWheel.motor  = motor;
        frontWheel.motor = motor;
    }
    void Start()
    {
        wheel             = GameObject.Find("carbody").GetComponents <WheelJoint2D>();
        motor             = wheel[0].motor; //for first tire
        wheel[0].useMotor = false;

        motor             = wheel[1].motor; //for second tire
        wheel[1].useMotor = false;
    }
Esempio n. 24
0
    public void leftButtonDown()
    {
        leftJointMotor = leftFlipper.motor;

        leftJointMotor.motorSpeed = -500;

        leftFlipper.motor = leftJointMotor;
        flipper.PlayOneShot(flipperSound, 0.5f);
    }
Esempio n. 25
0
 // Update is called once per frame
 void Update()
 {
     if (page == 1)
     {
         if (mcHJ.limitState == JointLimitState2D.UpperLimit)
         {
             mcdummyJM            = mcHJ.motor;
             mcdummyJM.motorSpeed = -20f;
             mcHJ.motor           = mcdummyJM;
         }
         else if (mcHJ.limitState == JointLimitState2D.LowerLimit)
         {
             mcdummyJM            = mcHJ.motor;
             mcdummyJM.motorSpeed = 20f;
             mcHJ.motor           = mcdummyJM;
         }
         if (!firinganimrunning)
         {
             firinganimrunning = true;
             RunFiringAnim();
         }
     }
     else if (page == 2)
     {
         if (!slimeColpg2running)
         {
             slimeColpg2running = true;
             angDegPg23         = 328f;
             MoveSlime();
         }
     }
     else if (page == 3)
     {
         if (!slimeColpg3running)
         {
             Debug.Log("Page 3 Bool not true");
             slimeColpg3running = true;
             Debug.Log("Page 3 Bool turned true");
             angDegPg23 = 328f;
             StopTile();
             MoveSlime();
             MoveTile();
         }
     }
     else if (page == 4)
     {
         if (!slimeColpg4running)
         {
             Debug.Log("Page 4 Bool not true");
             slimeColpg4running = true;
             Debug.Log("Page 4 Bool turned true");
             angDegPg4 = 310f;
             MoveSlimePg4();
         }
     }
 }
Esempio n. 26
0
    // Update is called once per frame
    void Update()
    {
        float axisH = Input.GetAxis("Horizontal");

        JointMotor2D motor = wheel.motor;

        motor.motorSpeed = -axisH * motorSpeed;

        wheel.motor = motor;
    }
 // Use this for initialization
 void Start()
 {
     FlipperSpeed         = 3000f;
     hinge                = GetComponent <HingeJoint2D>();
     motor                = hinge.motor;
     motor.motorSpeed     = 3000f;
     motor.maxMotorTorque = FlipperSpeed;
     hinge.motor          = motor;
     Free = true;
 }
    void Start()
    {
        rg2D    = GetComponent <Rigidbody2D>();
        wheel   = GetComponent <WheelJoint2D>();
        motorON = wheel.useMotor;

        motor = new JointMotor2D();
        motor.maxMotorTorque = 10000;
        wheel.motor          = motor;
    }
Esempio n. 29
0
    public void rightButtonDown()
    {
        rightJointMotor = rightFlipper.motor;

        rightJointMotor.motorSpeed = 500;

        rightFlipper.motor = rightJointMotor;

        flipper.PlayOneShot(flipperSound, 0.5f);
    }
Esempio n. 30
0
 private void SwingLeft()
 {
     swordMotor                = swordSwing.motor;
     swordMotor.motorSpeed     = -(attackSpeed * 20);
     swordMotor.maxMotorTorque = attackPower;
     swordSwing.motor          = swordMotor;
     attackSpeed               = 0f;
     charging = false;
     //thrustPowerText.text = attackSpeed.ToString();
 }