示例#1
0
    // Update is called once per frame
    void Update()
    {
        Vector2 curMov = new Vector2();

        rb2d.GetVector(curMov);
        curMov.x = -curMov.x;
        curMov.y = -curMov.y;
        rb2d.AddForce(curMov);

        //Basic Movement
        Vector2 movement = new Vector2();

        if (Input.GetAxis("Horizontal") > 0)// && checkEdge(new Vector2(-7.5f, 3.5f)))
        {
            movement.x = speed;
        }
        if (Input.GetAxis("Horizontal") < 0 && checkEdge(new Vector2(-7.5f, 3.5f)))
        {
            movement.x = -speed;
        }
        if (Input.GetAxis("Vertical") > 0 && checkEdge(new Vector2(-7.5f, 3.5f)))
        {
            movement.y = speed;
        }
        if (Input.GetAxis("Vertical") < 0)// && checkEdge(new Vector2(-7.5f, 3.5f)))
        {
            movement.y = -speed;
        }

        depthScaling();
        rb2d.AddForce(movement);
    }
示例#2
0
    void aggro_AI()
    {
        Vector3    vectorToTarget = player.transform.position - gameObject.transform.position;
        float      angleToTarget  = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg;
        Quaternion q = Quaternion.AngleAxis(angleToTarget - 90, Vector3.forward);
        float      force;

        if (angleToTarget < 0)
        {
            force = Mathf.Lerp(3, 0, angleToTarget / 180f);
        }
        else
        {
            force = Mathf.Lerp(0, 3, angleToTarget / 180f);
        }

        gameObject.transform.rotation = Quaternion.RotateTowards(gameObject.transform.rotation, q, force);

        body.drag = 0;
        if (vectorToTarget.magnitude > desiredDistance)
        {
            if (body.GetVector(vectorToTarget).magnitude < 30)
            {
                body.AddForce(gameObject.transform.up * 1);
            }
            else
            {
                body.drag = 0.5f;
            }
        }
        else
        {
            body.AddForce(gameObject.transform.up * -1);
        }
    }
    void processControls()
    {
        if (Input.touchCount > 0)
        {
            Vector2 dir = singleTapPoint - transform.position;
            transform.up = -dir;
            mouseClicked = false;
            shootSignal  = true;
        }
        else if (mouseClicked)
        {
            Vector2 dir = singleClickPoint - transform.position;
            transform.up = -dir;
            mouseClicked = false;
            shootSignal  = true;
        }
        else
        {
            player.AddForce(controllerForce, ForceMode2D.Force);
            player.AddTorque(getPlayerTorque(controllerRotate) * forceFactorOnRotate * 3,
                             ForceMode2D.Force);
            player.AddTorque(player.GetVector(player.velocity).x *forceFactorOnRotate / 3,
                             ForceMode2D.Force);

            if (shootSignal)
            {
                player.AddRelativeForce(new Vector2(0f, -shotImpulse));
                shootSignal = false;
            }
        }
    }
    void correct_rigidbody_rotation()
    {
        float angle_correction = 0.0f;
        float scalar_product   = 0.0f;
        float module_a         = 0.0f;
        float module_b         = 0.0f;
        float cos_angle        = 0.0f;

        getVector = _rigidbody2D.GetVector(_vector2_curr_dir);

        scalar_product = getVector.x * _vector2_dir_north.x + getVector.y * _vector2_dir_north.y;
        module_a       = Mathf.Sqrt(Mathf.Pow(getVector.x, 2.0f) + Mathf.Pow(getVector.y, 2.0f));
        module_b       = Mathf.Sqrt(Mathf.Pow(_vector2_dir_north.x, 2.0f) + Mathf.Pow(_vector2_dir_north.y, 2.0f));
        cos_angle      = scalar_product / (module_a * module_b);

        angle_correction = Mathf.Acos(cos_angle);
        angle_correction = angle_correction * Mathf.Rad2Deg;


        if ((_vector2_dir_north.x * getVector.y - _vector2_dir_north.y * getVector.x) >= 0.0f)   //check sign of angle (clockwize = -1,  counterwize = 1)
        {
            _rigidbody2D.MoveRotation(_rigidbody2D.rotation + angle_correction);
        }
        else
        {
            _rigidbody2D.MoveRotation(_rigidbody2D.rotation - angle_correction);
        }
    }
        // Use this for calculate
        public override void OnCalculate()
        {
            Rigidbody2D rigidbody2D = _Rigidbody2D.value;

            if (rigidbody2D != null)
            {
                _Result.SetValue(rigidbody2D.GetVector(_Vector.value));
            }
        }
示例#6
0
    static int GetVector(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        Rigidbody2D obj  = LuaScriptMgr.GetNetObject <Rigidbody2D>(L, 1);
        Vector2     arg0 = LuaScriptMgr.GetNetObject <Vector2>(L, 2);
        Vector2     o    = obj.GetVector(arg0);

        LuaScriptMgr.PushValue(L, o);
        return(1);
    }
示例#7
0
    void Gravity()
    {
        star.GetVector(Direction);
        Direction = (star.position - Player.position);
        star.GetComponent <Rigidbody2D>().GetVector(Direction);
        Distance = Direction.magnitude;
        if (Distance == 0)
        {
            return;
        }
        magForceofGravity = G * (Player.mass * star.mass) / (Distance * Distance);
        forceOfGravity    = Direction.normalized * magForceofGravity;

        Player.AddForce(forceOfGravity);
    }
示例#8
0
    public IEnumerator DragBack() //Отталкиваем героя(передаём позицию врага в векторе)
    {
        int X = Player.GetComponent <Animator>().GetInteger("Vector");

        if (!Pushed && CanWalk)
        {
            CanWalk = false;
            Pushed  = true;
            Rigi.AddForce((Rigi.GetVector(VecTest)).normalized * 50f, ForceMode2D.Force);
            yield return(new WaitForSecondsRealtime(0.01f));

            Rigi.drag = 100;
            CanWalk   = true;
        }
    }
    // Update is called once per frame
    void Update()
    {
        Vector2 curMov = new Vector2();

        rb2d.GetVector(curMov);
        curMov.x = -curMov.x;
        curMov.y = -curMov.y;
        rb2d.AddForce(curMov);


        //Basic Movement
        Vector2 movement = new Vector2();

        if (Input.GetAxis("Horizontal") > 0) //&& checkEdge2(new Vector2(7.5f, -3.5f)))
        {
            movement.x = speed;
        }
        if (Input.GetAxis("Horizontal") < 0)// && checkEdge(new Vector2(-7.5f, -1.5f)))
        {
            movement.x = -speed;
        }
        if (Input.GetAxis("Vertical") > 0)// && checkEdge(new Vector2(-7.5f, -1.5f)))
        {
            movement.y = speed;
        }
        if (Input.GetAxis("Vertical") < 0)// && checkEdge2(new Vector2(7.5f, -3.5f)))
        {
            movement.y = -speed;
        }

        rb2d.AddForce(movement);

        if (Input.GetKey(KeyCode.Q))
        {
            HB.DamageHealth(1);
        }

        UpdateHealth();
    }
示例#10
0
 private Vector2 GetRelativeVelocity(Vector2 position, Rigidbody2D a, Rigidbody2D b)
 {
     return(a.GetRelativePointVelocity(a.GetVector(position)) - b.GetRelativePointVelocity(b.GetVector(position)));
 }