Example #1
0
        public override void PlayerControl(Input input)
        {
            swordNode.movement.active = false;
            //sword.body.velocity = Utils.AngleToVector(sword.body.orient + (float)Math.PI/2) * 100;
            swordNode.body.velocity = swordNode.body.effvelocity * nodeKnockback;
            Vector2R rightstick = input.GetRightStick().toV2R();

            if (rightstick.LengthSquared() > 0.9 * 0.9)
            {
                movingStick = true;
                target      = rightstick;
                //enabled = true;
                target.Normalize();
                target            *= distance;
                target            += parent.body.pos;
                swordNode.body.pos = Vector2R.Lerp(swordNode.body.pos, target, 0.1f);
                //sword.body.pos = target + parent.body.pos;
                Vector2R result = swordNode.body.pos - parent.body.pos;
                swordNode.body.SetOrientV2(result);
            }
            else
            {
                movingStick = false;
                //enabled = false;
                Vector2R restPos = new Vector2R(parent.body.radius, 0).Rotate(parent.body.orient) + parent.body.pos;
                swordNode.body.pos    = Vector2R.Lerp(swordNode.body.pos, restPos, 0.1f);
                swordNode.body.orient = GMath.AngleLerp(swordNode.body.orient, parent.body.orient, 0.1f);
            }
            //sword.body.pos = position;
        }
Example #2
0
        public static void TurnTowardsDirection(Node node, Vector2R direction, bool flip, float lerpPercent)
        {
            if (direction == Vector2R.Zero)
            {
                return;
            }
            if (flip)
            {
                direction *= new Vector2R(-1, -1);
            }
            float    oldAngle    = VMath.VectorToAngle(node.body.velocity);
            float    newAngle    = VMath.VectorToAngle(direction);
            float    lerpedAngle = GMath.AngleLerp(oldAngle, newAngle, lerpPercent / 100f);
            Vector2R finalDir    = VMath.AngleToVector(lerpedAngle);

            node.body.velocity = VMath.Redirect(node.body.velocity, finalDir);
        }
Example #3
0
        public override void PlayerControl(Input input)
        {
            Vector2R stick  = input.GetLeftStick().toV2R();
            Vector2R stick2 = input.GetRightStick().toV2R();

            //if (node != bigtony) node.collision.colliders["trigger"].radius = body.radius * 1.5f;
            //else node.collision.colliders["trigger"].radius = body.radius * 1.2f;
            //bool clicked = false;
            //clicked = hc.newHalfPadState.Btn3 == ButtonState.Pressed || hc.newHalfPadState.Btn1 == ButtonState.Pressed;
            //
            //if (clicked)
            //{
            //    SwitchPlayer(stick);
            //}


            if (stick2.LengthSquared() > 0.6f * 0.6f)
            {
                v = VMath.VectorToAngle(stick2).between0and2pi();
                if (v == 0f)
                {
                    v = 0.00001f;
                }
            }
            else if (stick.LengthSquared() > 0.6f * 0.6f)
            {
                v = VMath.VectorToAngle(stick).between0and2pi();
                if (v == 0f)
                {
                    v = 0.00001f;
                }
            }
            float result = GMath.AngleLerp(parent.body.orient, v, 0.1f);

            parent.body.orient = (result);

            stick *= 0.4f;
            stick *= absaccel;
            if ((parent.body.velocity.X != 0 || parent.body.velocity.Y != 0))
            {
                stick += parent.body.velocity * -friction;
            }
            stick *= parent.body.mass;
            //todo: update maxvel?
            parent.body.ApplyForce(stick);
        }