Exemple #1
0
    void doRopePhysics(playerMovment p1, playerMovment p2, float delta)
    {
        if (ropeLength <= p1.Position.DistanceTo(p2.Position))
        {
            Vector2 ropePullVector = (p2.Position - p1.Position).Normalized();
            // tug on other player
            if (ropePullVector.Dot(p1.velocity) < 0)
            {
                if (p1.isAnchored && !p2.isAnchored)
                {
                    p2.velocity += p1.velocity * 0.5f;
                    // p2.MoveAndSlide(p1.velocity * 0.5f, new Vector2(0, -1));
                    p1.velocity *= 0.5f;
                }
            }

            if (ropeLength <= p1.Position.DistanceTo(p2.Position))
            {
                Vector2 parallelPart = (p1.velocity.Dot(ropePullVector) / ropePullVector.Dot(ropePullVector)) * ropePullVector;
                if (parallelPart.Dot(ropePullVector) < 0)
                {
                    p1.velocity -= parallelPart;
                }
            }
        }



        if (p1.hitNonWall())
        {
            p1.velocity    = new Vector2(0, 0);
            p1.velocity.y += delta * p1.gravity;
            p1.velocity.y  = Math.Min(p1.velocity.y, p1.maxYVel);
        }
    }
Exemple #2
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     p1       = (playerMovment)(KinematicBody2D)GetNode(player1);
     p2       = (playerMovment)(KinematicBody2D)GetNode(player2);
     ropeDraw = (Line2D)GetNode(ropeDrawPath);
 }