コード例 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //Debug.Log(transform.position);
        Matrix4x4 m    = cam.projectionMatrix;
        Vector3   vec2 = m * transform.position;

        vec2.z = transform.position.z;
        // Debug.Log(vec2);
        Vector3 vec1 = Input.mousePosition;

        vec1.x -= .5f * Screen.width;
        vec1.y -= .5f * Screen.height;
        vec1.x /= .5f * Screen.width;
        vec1.y /= .5f * Screen.height;
        Vector3 force = vec1 - vec2;

        //Debug.Log(vec1);
        force.x = force.x * 900f - 15 * rb.velocity.x;
        force.y = force.y * 900f - 15 * rb.velocity.y;
        force.z = force.z * 90f - .15f * rb.velocity.z;
        rb.AddForce(force);
    }
コード例 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (targetBody == null)
        {
            return;
        }

        if (positionToForce.Equals(Vector3.zero))
        {
            targetBody.AddForce(force);
        }
        else
        {
            targetBody.AddForceAtPosition(force, positionToForce);
        }

        targetBody.AddRelativeForce(relativeForce);
        targetBody.AddTorque(torque);
        targetBody.AddRelativeTorque(relativeTorque);

        for (var index = 0; index < targetBody.jointForce.dofCount; index++)
        {
            jointForce[index] = targetBody.jointForce[index];
        }
        for (var index = 0; index < targetBody.jointAcceleration.dofCount; index++)
        {
            jointAcceleration[index] = targetBody.jointAcceleration[index];
        }
        for (var index = 0; index < targetBody.jointVelocity.dofCount; index++)
        {
            jointVelocity[index] = targetBody.jointVelocity[index];
        }
        for (var index = 0; index < targetBody.jointPosition.dofCount; index++)
        {
            jointPosition[index] = targetBody.jointPosition[index];
        }
    }