public void Forces()
    {
        Vector2 force = Vector2.ClampMagnitude(targetPos * multiplier, clamp) * CanMove;

        if (body.GetRelativePointVelocity(forcePoint).magnitude < maxSpeed)
        {
            body.AddForceAtPosition(force, ForcePoint, ForceMode2D.Impulse);
        }
    }
예제 #2
0
        // Use this for calculate
        public override void OnCalculate()
        {
            Rigidbody2D rigidbody2D = _Rigidbody2D.value;

            if (rigidbody2D != null)
            {
                _Result.SetValue(rigidbody2D.GetRelativePointVelocity(_RelativePoint.value));
            }
        }
예제 #3
0
    static int GetRelativePointVelocity(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        Rigidbody2D obj  = LuaScriptMgr.GetNetObject <Rigidbody2D>(L, 1);
        Vector2     arg0 = LuaScriptMgr.GetNetObject <Vector2>(L, 2);
        Vector2     o    = obj.GetRelativePointVelocity(arg0);

        LuaScriptMgr.PushValue(L, o);
        return(1);
    }
예제 #4
0
    //void OnTriggerEnter2D(Collider2D collider)
    void OnCollisionEnter2D(Collision2D collision)
    {
        var collidedWith = collision.collider;

        if (collidedWith.gameObject.tag == "Player")
        {
            var hitVelocity = selfRigidBody2D.GetRelativePointVelocity(collidedWith.attachedRigidbody.position)
                              - collidedWith.attachedRigidbody.velocity;
            var hitVelocityMagnitude = hitVelocity.magnitude;
            var playerController     = collidedWith.GetComponent <FightPlayerController>();
            playerController.TakeDamage(hitVelocityMagnitude);
        }
    }
예제 #5
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E) && currentPayload != null && currentPayloadCargo == null)
        {
            currentPayload.transform.SetParent(transform, true);

            Rigidbody2D cb = currentPayload.GetComponent <Rigidbody2D> ();
            //Rigidbody2D lb = GetComponentInParent<Rigidbody2D>();

            crateMass = cb.mass;

            GetComponentInParent <Rigidbody2D> ().mass += crateMass;

            Destroy(cb);

            currentPayloadCargo = currentPayload;

            currentPayload = null;
            hasCargo       = true;
            pickupInstrictions.gameObject.SetActive(false);

            return;
        }
        if (Input.GetKeyDown(KeyCode.E) && currentPayloadCargo != null)
        {
            Vector2 cratePosition = currentPayloadCargo.transform.position;

            currentPayloadCargo.transform.SetParent(null, true);

            currentPayloadCargo.transform.position = cratePosition;

            Rigidbody2D cb = currentPayloadCargo.gameObject.AddComponent <Rigidbody2D> ();

            cb.mass = crateMass;

            Rigidbody2D landerBody = GetComponentInParent <Rigidbody2D> ();

            landerBody.mass -= crateMass;

            //landerBody.GetRelativePointVelocity (transform.localPosition);

            Vector2 crateVelocity = landerBody.GetRelativePointVelocity(transform.localPosition);

            cb.velocity = crateVelocity;

            currentPayloadCargo = null;
            hasCargo            = false;

            return;
        }
    }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        velocity = body.GetRelativePointVelocity(relative_point);
        mag      = velocity.magnitude;
        if (mag > TOP_SPEED)
        {
            body.velocity = velocity.normalized * TOP_SPEED;
        }
        // print(Mathf.Sin(t + (body.GetRelativePoint(relative_point).x)));

        change_v      = new Vector2(LEFT.x, Mathf.Sin(t + (body.GetRelativePoint(relative_point).x)));
        body.velocity = change_v;
        t            += Time.deltaTime / 2;
    }
예제 #7
0
    // Update is called once per frame
    void Update()
    {
        velocity = body.GetRelativePointVelocity(relative_point);
        mag      = velocity.magnitude;

        float topSpeed = FORWARD_BOOST_FLAG ? TOP_SPEED * 2f : TOP_SPEED;

        if (mag > topSpeed)
        {
            body.velocity = velocity.normalized * topSpeed;
        }

        body.AddForce(Vector2.up * FORCE_APPLIED * player.GetAxis(RewiredConsts.Action.MOVEVERTICAL));
        body.AddForce(Vector2.right * FORCE_APPLIED * player.GetAxis(RewiredConsts.Action.MOVEHORIZONTAL));
        body.AddForce(Vector2.right * CONSTANT_SCROLL_FORCE);


        if (player.GetButtonDown(RewiredConsts.Action.SWIM) && Time.time - boostTime > BOOST_COOLDOWN)
        {
            boostTime = Time.time;
            AkSoundEngine.PostEvent("FishSpeedBurst", gameObject);
        }
        if (player.GetButton(RewiredConsts.Action.SWIM) && Time.time - boostTime < BOOST_DURATION)
        {
            body.AddForce(Vector2.right * BOOST_FORCE);
            FORWARD_BOOST_FLAG = true;
            var emission = bubbleTrail.emission;
            emission.enabled = true;
        }
        else
        {
            FORWARD_BOOST_FLAG = false;
            var emission = bubbleTrail.emission;
            emission.enabled = false;
        }
        if (player.GetButtonDown(RewiredConsts.Action.FIRE))
        {
            if (prawns.Count > 0)
            {
                prawns[prawns.Count - 1].Shoot(transform.position + Vector3.right * 0.1f, Vector3.right);
                prawns.RemoveAt(prawns.Count - 1);
                Game.Instance.player.ShrimpCount = prawns.Count;
                AkSoundEngine.PostEvent("ShrimpCanon", gameObject);
            }
        }
    }
예제 #8
0
    void LateUpdate()
    {
        // If no target, abort and remove component.
        if (target == null)
        {
            Debug.LogWarning("WeaponFollow script had no target. Script should be created using WeaponFollow.Attach()");
            Destroy(this);             // Destroy this component
            return;
        }

        // Calcualte the offset and bobbing
        Vector2 usableOffset = new Vector2(
            target.facingRight ? offset.x : -offset.x,
            offset.y + Mathf.Sin(bobTime * BOB_SPEED) * BOB_AMOUNT
            );

        // The bob time
        bobTime += Mathf.Min(Mathf.Abs(targetRigid.GetRelativePointVelocity(Vector2.right).x), BOB_INSENSITIVITY) / BOB_INSENSITIVITY;

        // Apply position and rotation
        transform.position = target.transform.position + target.transform.TransformVector(usableOffset);
        transform.rotation = target.transform.rotation;
    }
예제 #9
0
 private Vector2 GetRelativeVelocity(Vector2 position, Rigidbody2D a, Rigidbody2D b)
 {
     return(a.GetRelativePointVelocity(a.GetVector(position)) - b.GetRelativePointVelocity(b.GetVector(position)));
 }
예제 #10
0
    // Update is called once per frame
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }


        Rigidbody2D rb = this.GetComponent <Rigidbody2D>();

        rMult = rb.GetRelativePointVelocity(Vector2.zero).magnitude *Time.deltaTime;
        if (Input.GetAxis("Vertical") != 0)
        {
            rb.AddRelativeForce(new Vector2(0, Input.GetAxis("Vertical")) * Time.deltaTime * speedMultiplier * 1000);
            if (Input.GetAxis("Vertical") > 0 && Input.GetAxis("Jump") < 1)
            {
                changeSpeed(1);
            }
            else if (Input.GetAxis("Vertical") < 0 && Input.GetAxis("Jump") < 1)
            {
                changeSpeed(-1);
            }
        }
        else if (Input.GetAxis("Jump") < 1)
        {
            changeSpeed(0);
        }
        if (Input.GetAxis("Jump") > 0)
        {
            changeSpeed(2);
            rb.AddRelativeForce(new Vector2(0, Time.deltaTime * speedMultiplier * 100), ForceMode2D.Impulse);
        }

        rotation = Vector2.Angle(rb.GetRelativePointVelocity(Vector2.zero), rb.GetRelativeVector(Vector2.up));
        if (rotation < 90)
        {
            isFwd = true;
            if (rotation > 45)
            {
                isDrifting = true;
            }
            else
            {
                isDrifting = false;
            }
        }
        else if (rotation > 90)
        {
            isFwd = false;
            if (rotation < 135)
            {
                isDrifting = true;
            }
            else
            {
                isDrifting = false;
            }
        }

        if (isDrifting)
        {
            rMult = rMult / 3;
        }

        if (isFwd)
        {
            rMult = 0 - rMult;
        }

        if (Input.GetAxis("Horizontal") != 0)
        {
            rb.AddTorque(rotationMultiplier * rMult * Input.GetAxis("Horizontal"));
            if (!isTurning)
            {
                animator.SetBool("turning", true);
                isTurning = true;
            }
        }
        else if (isTurning)
        {
            animator.SetBool("turning", false);
            isTurning = false;
        }
    }