Beispiel #1
0
    protected override void Start()
    {
        base.Start();

        // Get the sprite from the child components so that we can rotate it even if we have a slider joint
        SpriteRenderer sprite = this.GetComponentInChildren <SpriteRenderer>();

        if (sprite != null)
        {
            this.renderTransform = sprite.transform;
        }

        // Get the slider joint that prevents any Y movement
        SliderJoint2D joint = this.GetComponent <SliderJoint2D>();

        if (joint != null)
        {
            joint.anchor = new Vector2(this.transform.position.x, -this.transform.position.y);
        }

        // Give it some velocity
        float       x    = directionX * this.Speed;
        Rigidbody2D body = this.GetComponent <Rigidbody2D>();

        if (body != null)
        {
            body.AddForce(new Vector2(x, 0));
        }
    }
    public Transform realClamppedJoystickInput; // The target position for this arm tip based on the joystick input

    // Use this for initialization
    void Start()
    {
        // Set up the 2D arm
        armBodyHingeJoint2D = armBodyJoint2D.GetComponent <HingeJoint2D>();        // Get the initial hinge joint 2D on the 2D arm-body joint
        targetArmBodyHingeJointMotor.maxMotorTorque = armBodyHingeJointMotorForce; // Set the max torque of the motor on the 2D hinge joint on the 2D arm-body joint
        armBodyHingeJoint2D.useMotor  = true;
        armBodyHingeJoint2D.useLimits = false;
        armTipSliderJoint2D           = armTip2D.GetComponent <SliderJoint2D>();   // Get the initial slider joint 2D on the 2D armTip
        targetArmTipSliderJointMotor.maxMotorTorque = armTipSliderJointMotorForce; // Set the max torque of the motor on the 2D slider joint on the 2D armTip
        armBodyHingeJoint2D.useMotor = true;
        // Set the 2D armTip slider joint's translation limits
        JointTranslationLimits2D armTipSliderJointLimit = new JointTranslationLimits2D();

        armTipSliderJointLimit.min    = 0;
        armTipSliderJointLimit.max    = armMaxLength;
        armTipSliderJoint2D.limits    = armTipSliderJointLimit;
        armTipSliderJoint2D.useLimits = true;

        //CreateBackUpHingeJoint2D();

        // Set up the flags
        canGrabObject = true;

        // Set up the arm stretch limiter
        if (isLeftArm)
        {
            //armTipStretchLimiter.localScale = armTipStretchLimiter.localScale * armMaxLength * 2;
        }
    }
        public void OnSceneGUI()
        {
            SliderJoint2D target = (SliderJoint2D)this.target;

            if (target.enabled)
            {
                Vector3 position = Joint2DEditor.TransformPoint(target.transform, (Vector3)target.anchor);
                Vector3 vector2  = position;
                Vector3 vector3  = position;
                Vector3 lhs      = (Vector3)Joint2DEditor.RotateVector2(Vector3.right, -target.angle - target.transform.eulerAngles.z);
                Handles.color = Color.green;
                if (target.useLimits)
                {
                    vector2 = position + ((Vector3)(lhs * target.limits.max));
                    vector3 = position + ((Vector3)(lhs * target.limits.min));
                    Vector3 vector5 = Vector3.Cross(lhs, Vector3.forward);
                    float   num     = HandleUtility.GetHandleSize(vector2) * 0.16f;
                    float   num2    = HandleUtility.GetHandleSize(vector3) * 0.16f;
                    Joint2DEditor.DrawAALine(vector2 + ((Vector3)(vector5 * num)), vector2 - ((Vector3)(vector5 * num)));
                    Joint2DEditor.DrawAALine(vector3 + ((Vector3)(vector5 * num2)), vector3 - ((Vector3)(vector5 * num2)));
                }
                else
                {
                    lhs      = (Vector3)(lhs * (HandleUtility.GetHandleSize(position) * 0.3f));
                    vector2 += lhs;
                    vector3 -= lhs;
                }
                Joint2DEditor.DrawAALine(vector2, vector3);
                base.OnSceneGUI();
            }
        }
Beispiel #4
0
    public void ReleaseObject()
    {
        Carriable     carriable   = CarriedObject.GetComponent <Carriable> ();
        float         fator       = (carriable.isHeavy()?1.5f:1);
        SliderJoint2D sliderJoint = GetComponent <SliderJoint2D>();

        sliderJoint.connectedBody = null;
        sliderJoint.enabled       = false;
        if (Crouched)
        {
            CarriedObject.GetComponent <Rigidbody2D> ().velocity = new Vector2(0, 0);
            CarriedObject.transform.rotation = new Quaternion(0, 0, 0, CarriedObject.transform.localRotation.w);
            CarriedObject.transform.position = new Vector2(transform.position.x + facingDirection * transform.localScale.x / 2 + facingDirection * CarriedObject.transform.localScale.x / 2, transform.position.y - transform.localScale.y + CarriedObject.transform.localScale.y + offsetCarryObjHero * fator);
        }
        else
        {
            CarriedObject.GetComponent <Rigidbody2D> ().velocity = new Vector2(rigidBody2D.velocity.x, 0);
            CarriedObject.GetComponent <Rigidbody2D> ().AddForce(new Vector2(fator * facingDirection * 5f, fator * 1f), ForceMode2D.Impulse);
        }
        Carrying                 = false;
        CarriedObject            = null;
        carriable.isBeingCarried = false;
        animator.SetBool("carry", false);

        isHoldingBox = false;
    }
Beispiel #5
0
        public new void OnSceneGUI()
        {
            SliderJoint2D sliderJoint2D = (SliderJoint2D)this.target;

            if (!sliderJoint2D.enabled)
            {
                return;
            }
            Vector3 vector  = Joint2DEditor.TransformPoint(sliderJoint2D.transform, sliderJoint2D.anchor);
            Vector3 vector2 = vector;
            Vector3 vector3 = vector;
            Vector3 vector4 = Joint2DEditor.RotateVector2(Vector3.right, -sliderJoint2D.angle - sliderJoint2D.transform.eulerAngles.z);

            Handles.color = Color.green;
            if (sliderJoint2D.useLimits)
            {
                vector2 = vector + vector4 * sliderJoint2D.limits.max;
                vector3 = vector + vector4 * sliderJoint2D.limits.min;
                Vector3 a  = Vector3.Cross(vector4, Vector3.forward);
                float   d  = HandleUtility.GetHandleSize(vector2) * 0.16f;
                float   d2 = HandleUtility.GetHandleSize(vector3) * 0.16f;
                Joint2DEditor.DrawAALine(vector2 + a * d, vector2 - a * d);
                Joint2DEditor.DrawAALine(vector3 + a * d2, vector3 - a * d2);
            }
            else
            {
                vector4 *= HandleUtility.GetHandleSize(vector) * 0.3f;
                vector2 += vector4;
                vector3 -= vector4;
            }
            Joint2DEditor.DrawAALine(vector2, vector3);
            base.OnSceneGUI();
        }
Beispiel #6
0
    private void Start()
    {
        isOutside = false;

        slide   = GetComponent <SliderJoint2D>();
        waiting = new Waiting(StartWait);
        storageVoid.InstMemory("float", 1, 3);


        storageVoid["0", "0"] = (p) =>
        {
            slide.anchor = new Vector2(0, anchorBrian);
            return(speedOther);
        };
        storageVoid["0", "1"] = (p) =>
        {
            slide.anchor = new Vector2(0, anchorEva);
            return(speedEva);
        };
        storageVoid["0", "2"] = (p) =>
        {
            slide.anchor = new Vector2(0, anchorZak);
            return(speedOther);
        };
    }
Beispiel #7
0
 // Use this for initialization
 void Start()
 {
     //get the sliderJoint2D component attached to the door object
     door = gameObject.GetComponent <SliderJoint2D>();
     //we will use the jointMotor2D to add speed and later set it back to the SliderJoint2D's motor as setting the motor speed of the sliderJoint2D doesn't work.
     doorMotor = door.motor;
 }
Beispiel #8
0
 private void Awake()
 {
     rb            = GetComponent <Rigidbody2D>();
     sliderJoint2D = GetComponent <SliderJoint2D>();
     sliderJoint2D.connectedAnchor = transform.position - transform.up * downDistance;
     initialPos = rb.position;
 }
Beispiel #9
0
    void ConfigureWheel()
    {
        gameObject.GetComponent <SliderJoint2D>().connectedBody = Parent;
        gameObject.GetComponent <SpringJoint2D>().connectedBody = Parent;
        Wheel.GetComponent <HingeJoint2D>().connectedBody       = GetComponent <Rigidbody2D>();

        SliderJoint2D sliderJoint = gameObject.GetComponent <SliderJoint2D>();

        sliderJoint.enableCollision = true;
        sliderJoint.connectedAnchor = new Vector2(transform.localPosition.x, transform.localPosition.y);

        sliderJoint.useLimits = true;
        JointTranslationLimits2D limit = new JointTranslationLimits2D();

        limit.min          = -DamperSize;
        limit.max          = DamperSize;
        sliderJoint.limits = limit;

        SpringJoint2D springJoint = gameObject.GetComponent <SpringJoint2D>();

        springJoint.enableCollision = true;
        springJoint.connectedAnchor = new Vector2(transform.localPosition.x, transform.localPosition.y + (-DamperSize));

        springJoint.frequency = DamperStiffness;

        gameObject.transform.parent = null;
        Wheel.transform.parent      = null;
    }
Beispiel #10
0
 void Start()
 {
     slider = GetComponent <SliderJoint2D>();
     motor  = slider.motor;
     min    = slider.limits.min;
     min    = slider.limits.min;
 }
Beispiel #11
0
    private void CarryObject()
    {
        Carriable carriable    = heroInterac.carriableObject.GetComponent <Carriable> ();
        bool      objIsInFront = heroInterac.carriableObject.transform.position.x * facingDirection > transform.position.x * facingDirection;
        float     fator        = carriable.isHeavy()?1.5f:1f;

        if (carriable != null && !carriable.isBeingCarried && objIsInFront && (!carriable.isHeavy() || this.IsStrong()))
        {
            Vector2    ls   = heroInterac.transform.localScale;
            Vector2    a    = new Vector2(transform.position.x - ls.x / 2, transform.position.y + transform.localScale.y + ls.y + offsetCarryObjHero * fator - ls.y / 2);
            Vector2    b    = new Vector2(transform.position.x + ls.x / 2, transform.position.y + transform.localScale.y + ls.y + offsetCarryObjHero * fator + ls.y / 2);
            Collider2D coll = Physics2D.OverlapArea(a, b);
            if (coll == null)
            {
                Carrying      = true;
                CarriedObject = heroInterac.carriableObject;
                SliderJoint2D sliderJoint = GetComponent <SliderJoint2D> ();
                CarriedObject.transform.rotation = new Quaternion(0, 0, 0, CarriedObject.transform.localRotation.w);
                CarriedObject.transform.position = new Vector2(transform.position.x, transform.position.y + transform.localScale.y + CarriedObject.transform.localScale.y + offsetCarryObjHero * fator);
                sliderJoint.connectedBody        = CarriedObject.GetComponent <Rigidbody2D> ();
                sliderJoint.enabled      = true;
                carriable.isBeingCarried = true;
                StopPush();
                animator.SetBool("carry", true);
            }
        }
    }
        void Awake()
        {
            _slider = GetComponent <SliderJoint2D>();
            _rbody  = GetComponent <Rigidbody2D>();
            _coll   = GetComponentInChildren <grabot_tracks_collider>();

            _tracks_mat = tracks_mesh_renderer.materials[material_id];
        }
Beispiel #13
0
 void Start()
 {
     position        = transform.position;
     rigidbody       = GetComponent <Rigidbody2D>();
     joint           = GetComponent <SliderJoint2D>();
     connectedBodies = new List <Rigidbody2D>();
     target          = targets[targetIndex];
 }
Beispiel #14
0
 // Use this for initialization
 void Awake()
 {
     startPos               = transform.position;
     targetPos              = transform.GetChild(0).transform.position;
     smashSpeed             = 70f;
     retractSpeed           = 10f;
     distThresh             = 0.015f;
     slider                 = GetComponent <SliderJoint2D> ();
     slider.connectedAnchor = startPos;
 }
Beispiel #15
0
    static int GetMotorForce(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        SliderJoint2D obj  = LuaScriptMgr.GetNetObject <SliderJoint2D>(L, 1);
        float         arg0 = (float)LuaScriptMgr.GetNumber(L, 2);
        float         o    = obj.GetMotorForce(arg0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
    void Start()
    {
        if (!m_Source)
        {
            return;
        }

        m_Text        = GetComponent <TextMesh> ();
        m_Body        = m_Source.GetComponent <Rigidbody2D> ();
        m_SliderJoint = m_Source.GetComponent <SliderJoint2D> ();
    }
Beispiel #17
0
 // Use this for initialization
 void Start()
 {
     // So box will not push it down.
     //GetComponent<SliderJoint2D>().enabled = false;
     mySlider = GetComponent <SliderJoint2D>();
     p        = new GameObject[2];
     p[0]     = GameObject.FindGameObjectWithTag("Player");
     p[1]     = GameObject.FindGameObjectWithTag("Player2");
     //InitialDestination = transform.position;
     //targetPosition = FinalDestination.position;
 }
Beispiel #18
0
 private bool CheckLimits(SliderJoint2D slider)
 {
     if (slider.limitState == JointLimitState2D.LowerLimit || slider.limitState == JointLimitState2D.UpperLimit)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
    private void AllowMovementByPanning(Vector2 axis)
    {
        motionIsUsed   = true;
        panningAxis    = axis;
        rotationMethod = PanAlongLine;

        this.gameObject.AddComponent <SliderJoint2D>();
        SliderJoint2D slider = GetComponent <SliderJoint2D>();

        slider.anchor = axis;
    }
Beispiel #20
0
    // Start is called before the first frame update
    void Start()
    {
        rb          = GetComponent <Rigidbody2D>();
        swordColl   = GetComponent <PolygonCollider2D>();
        swordSprite = GetComponent <SpriteRenderer>();

        playerComp = player.GetComponent <PlayerTest>();

        swordIdle   = GetComponent <FixedJoint2D>();
        swordThrust = GetComponent <SliderJoint2D>();
        swordSwing  = GetComponent <HingeJoint2D>();
    }
Beispiel #21
0
 void Start()
 {
     slider           = GetComponent <SliderJoint2D>();
     lim              = slider.limits;
     speed            = (lim.max - lim.min) / period;
     m.maxMotorTorque = slider.motor.maxMotorTorque;
     m.motorSpeed     = speed * orientation;
     slider.motor     = m;
     marginTime       = 0;
     rb       = GetComponent <Rigidbody2D>();
     minSpeed = (slider.motor.maxMotorTorque / rb.mass) * Time.fixedDeltaTime;
 }
Beispiel #22
0
 void Start()
 {
     Slider          = GetComponentInParent <SliderJoint2D>();
     Slider.useMotor = true;
     defaultY        = Slider.attachedRigidbody.position.y;
     yPlusDelta      = defaultY + Slider.limits.max;
     if (startOffset >= 0f && startOffset <= 1f)
     {
         Vector2 offsetVector = Slider.attachedRigidbody.position;
         offsetVector.y += (Slider.limits.max * startOffset);
         Slider.attachedRigidbody.position = offsetVector;
     }
 }
 private bool dir = true;//caso true indo, caso false voltando..
 // Start is called before the first frame update
 void Start()
 {
     sliderJoint2 = GetComponent <SliderJoint2D>();
     tempMotor    = sliderJoint2.motor;
     if (tempMotor.motorSpeed < 0)
     {
         dir = false;
     }
     else if (tempMotor.motorSpeed >= 0)
     {
         dir = true;
     }
 }
 private void Start()
 {
     slider  = GetComponent <SliderJoint2D>();
     upMotor = new JointMotor2D()
     {
         maxMotorTorque = 10000,
         motorSpeed     = liftSpeed
     };
     downMotor = new JointMotor2D()
     {
         maxMotorTorque = 10000,
         motorSpeed     = -liftSpeed
     };
 }
Beispiel #25
0
    private void ChangeSliderDirection()
    {
        SliderJoint2D slider = (SliderJoint2D)joint;
        JointMotor2D  motor  = new JointMotor2D();

        motor.maxMotorTorque = 10000f;
        if (slider.motor.motorSpeed != 0 && ready && CheckLimits(slider))
        {
            motor_speed     *= -1f;
            motor.motorSpeed = motor_speed;
            slider.motor     = motor;
            StartCoroutine(Wait(0.1f));
        }
    }
Beispiel #26
0
    LocomotionComponent AttachPiston(GameObject socket)
    {
        GameObject p = Instantiate(piston) as GameObject;

        p.transform.parent        = transform;
        p.transform.localPosition = socket.transform.localPosition;

        SliderJoint2D slider = p.GetComponent <SliderJoint2D>();

        slider.connectedBody   = rb;
        slider.connectedAnchor = socket.transform.localPosition;

        return(p.GetComponent <Piston>());
    }
Beispiel #27
0
        public void Start()
        {
            spring   = GetComponent <SpringJoint2D>();
            slider   = GetComponent <SliderJoint2D>();
            platform = spring.connectedBody;

            // set default distance and limits based on what we're connected to
            baseDistance     = transform.position.y - platform.transform.position.y;
            spring.distance  = baseDistance - 1;
            slider.useLimits = true;
            slider.limits    = new JointTranslationLimits2D()
            {
                min = -(baseDistance + 2), max = -(baseDistance - 1)
            };
        }
Beispiel #28
0
 // Use this for initialization
 void Start()
 {
     transform.FindChild("Collision").gameObject.tag = "MovingPlatform";
     gameObject.tag = "MovingPlatform";
     gameObject.AddComponent<Rigidbody2D>();
     body = gameObject.GetComponent<Rigidbody2D>();
     slider = gameObject.AddComponent<SliderJoint2D>();
     //slider.rigidbody2D = gameObject.GetComponent<Rigidbody2D>();
     body.mass = 150;
     gameObject.transform.position = new Vector2(transform.position.x - 20,transform.position.y);
     //gameObject.transform.position.x = gameObject.transform.position.x - 20;
     body.gravityScale = 150;
     body.isKinematic = false;
     body.fixedAngle = true;
 }
Beispiel #29
0
    public void HoldObject()
    {
        if (!isHoldingBox)
        {
            Bounds     bounds  = GetComponentInChildren <Renderer>().bounds;
            GameObject Carried = heroInterac.carriableObject;

            // Match the box postion and the hero facing direction: if
            // hero is not facing the box, he will not pick it up
            if (((Carried.transform.position.x > transform.position.x) && facingDirection == 1) ||
                ((Carried.transform.position.x < transform.position.x) && facingDirection == -1))
            {
                // Transform to avoid conflict with hero
                // position. Also ensure that the box will be at the
                // correct position on holding
                Carried.transform.position = new Vector2(transform.position.x + facingDirection * bounds.extents.x,
                                                         transform.position.y);
                Carried.transform.rotation = new Quaternion(0, 0, 0, Carried.transform.localRotation.w);

                SliderJoint2D sliderJoint = GetComponent <SliderJoint2D> ();
                sliderJoint.connectedBody = Carried.GetComponent <Rigidbody2D>();
                Bounds connectedBounds = sliderJoint.connectedBody.GetComponentInChildren <Renderer>().bounds;

                // Offset due to Sprite of the heroes. Difference between
                // the bound of interact collider and the animated pixels.
                float spriteOffset = 0.07f;

                // Joint must be positioned right in front of hero
                // considering his current facing direction
                sliderJoint.connectedAnchor = new Vector2(-facingDirection * (interactCollider.size.x / 2f + connectedBounds.extents.x - spriteOffset),
                                                          0);
                sliderJoint.enabled = true;

                isHoldingBox = true;
                animator.SetBool("pushStandingStill", true);
            }
        }

        else
        {
            SliderJoint2D sliderJoint = GetComponent <SliderJoint2D>();
            sliderJoint.connectedBody = null;
            sliderJoint.enabled       = false;
            isHoldingBox = false;
            animator.SetBool("pushStandingStill", false);
            StopPush();
        }
    }
Beispiel #30
0
    // Start is called before the first frame update
    void Start()
    {
        Physics2D.gravity = new Vector2(0, 0);
        //cam = Camera.main;
        rb = GetComponent <Rigidbody2D>();

        swordIdle   = sword.GetComponent <FixedJoint2D>();
        swordThrust = sword.GetComponent <SliderJoint2D>();
        swordSwing  = sword.GetComponent <HingeJoint2D>();

        //swordIdle.enabled = false;
        swordThrust.enabled = false;
        swordSwing.enabled  = false;

        //thrustPowerText.text = attackSpeed.ToString();
    }