public override void _Ready()
            {
                var windmillBase = new WindmillBase()
                {
                    Extents = BaseExtents
                };

                AddChild(windmillBase);

                var windmillBlade = new WindmillBlade()
                {
                    Extents  = BladeExtents,
                    Torque   = BladeTorque,
                    Position = windmillBase.Position - new Vector2(0, windmillBase.Extents.y)
                };

                AddChild(windmillBlade);

                var joint = new PinJoint2D()
                {
                    NodeA    = windmillBase.GetPath(),
                    NodeB    = windmillBlade.GetPath(),
                    Softness = 0
                };

                windmillBlade.AddChild(joint);
            }
            public override void _Ready()
            {
                var carBase = new CarBase();

                AddChild(carBase);

                var carLeftWheel = new Wheel();

                carLeftWheel.Position = carBase.Position + new Vector2((-carBase.BodySize.x / 2) + carLeftWheel.Radius, carBase.BodySize.y);
                AddChild(carLeftWheel);
                var leftJoint = new PinJoint2D()
                {
                    NodeA    = carBase.GetPath(),
                    NodeB    = carLeftWheel.GetPath(),
                    Softness = 0
                };

                carLeftWheel.AddChild(leftJoint);

                var carRightWheel = new Wheel();

                carRightWheel.Position = carBase.Position + new Vector2((carBase.BodySize.x / 2) - carRightWheel.Radius, carBase.BodySize.y);
                AddChild(carRightWheel);
                var rightJoint = new PinJoint2D()
                {
                    NodeA    = carBase.GetPath(),
                    NodeB    = carRightWheel.GetPath(),
                    Softness = 0
                };

                carRightWheel.AddChild(rightJoint);
            }
            public void LinkToParent(PhysicsBody2D parent, float softness = 0, float bias = 0)
            {
                var pinJoint = new PinJoint2D()
                {
                    NodeA    = parent.GetPath(),
                    NodeB    = GetPath(),
                    Softness = softness,
                    Bias     = bias
                };

                parent.AddChild(pinJoint);
            }
            public void LinkTarget(PhysicsBody2D target, float softness = 0, float bias = 0)
            {
                var pinJoint = new PinJoint2D()
                {
                    NodeA    = GetPath(),
                    NodeB    = target.GetPath(),
                    Softness = softness,
                    Bias     = bias
                };

                AddChild(pinJoint);
            }
Esempio n. 5
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     rightUpperRod                   = GetNode <RigidBody2D>(rightUpperRodPath) as RigidBody2D;
     rightLowerRod                   = GetNode <RigidBody2D>(rightLowerRodPath) as RigidBody2D;
     leftUpperRod                    = GetNode <RigidBody2D>(leftUpperRodPath) as RigidBody2D;
     leftLowerRod                    = GetNode <RigidBody2D>(leftLowerRodPath) as RigidBody2D;
     rightSphere                     = GetNode <RigidBody2D>(rightSpherePath) as RigidBody2D;
     leftSphere                      = GetNode <RigidBody2D>(leftSpherePath) as RigidBody2D;
     collar                          = GetNode <RigidBody2D>(collarPath) as RigidBody2D;
     centerRod                       = GetNode <RigidBody2D>(centerRodPath) as RigidBody2D;
     governorLowerLeftJoint          = GetNode <PinJoint2D>(governorLowerLeftJointPath) as PinJoint2D;
     governorLowerRightJoint         = GetNode <PinJoint2D>(governorLowerRightJointPath) as PinJoint2D;
     initialCollarHeight             = collar.Position.y;
     collarX                         = collar.Position.x;
     governorLowerLeftJointInitialY  = governorLowerLeftJoint.Position.y;
     governorLowerRightJointInitialY = governorLowerRightJoint.Position.y;
 }
            public override void _Ready()
            {
                ball1 = new SimpleBall()
                {
                    Radius   = Radius,
                    Position = new Vector2(-Distance, -Distance)
                };
                ball2 = new SimpleBall()
                {
                    Radius   = Radius,
                    Position = new Vector2(Distance, Distance)
                };
                AddChild(ball1);
                AddChild(ball2);

                var join = new PinJoint2D()
                {
                    NodeA    = ball1.GetPath(),
                    NodeB    = ball2.GetPath(),
                    Softness = 0.1f
                };

                ball1.AddChild(join);
            }
Esempio n. 7
0
    public void FireHook(Vector2 StartPosition, Vector2 EndPosition)
    {
        RigidBody2D Link     = (RigidBody2D)ChainLink.Duplicate();
        RigidBody2D NextLink = null;

        Link.Position       = StartPosition;
        Link.LinearVelocity = Vector2.Zero;
        Link.Visible        = true;
        AddChild(Link);

        Vector2 Direction = (EndPosition - StartPosition).Normalized();
        int     length    = CheckCollisions(StartPosition, EndPosition);

        PinJoint2D Joint = new PinJoint2D();

        Joint.Position = StartPosition - (Direction * LengthOfChainLink * (2f / 3f));
        AddChild(Joint);
        Joint.NodeA = _Player.GetPath();
        Joint.NodeB = Link.GetPath();

        Chain.Add(Joint);

        Joint          = new PinJoint2D();
        Joint.Softness = JointSoftness;
        Joint.Position = StartPosition - (Direction * LengthOfChainLink * (2f / 3f));

        for (int i = 0; i < length; i++)
        {
            NextLink           = (RigidBody2D)Link.Duplicate();
            NextLink.Position += (Direction * LengthOfChainLink);
            AddChild(NextLink);

            Chain.Add(NextLink);
            Chain.Add(Link);
            Chain.Add(Joint);

            Joint.NodeA = Link.GetPath();
            Joint.NodeB = NextLink.GetPath();

            Link = NextLink;

            AddChild(Joint);

            Vector2 OldPosition = Joint.Position;
            Joint          = new PinJoint2D();
            Joint.Softness = JointSoftness;
            Joint.Position = (OldPosition + (Direction * LengthOfChainLink));
        }

        Node2D hitNode = GetCollidingNode(StartPosition, EndPosition, NextLink.Position);

        if (hitNode != null)
        {
            GD.Print(hitNode.GetPath());
            PinJoint2D FinalJoint = new PinJoint2D();
            AddChild(FinalJoint);

            FinalJoint.Position = (NextLink.Position + (Direction * LengthOfChainLink * (2f / 3f)));
            FinalJoint.NodeA    = NextLink.GetPath();
            FinalJoint.NodeB    = hitNode.GetPath();

            Chain.Add(FinalJoint);
        }

        IsFired = true;
    }