Example #1
0
    /// <summary>
    /// Execute the action; actObj.
    /// </summary>
    /// <param name='actObj'>
    /// Object doing the action
    /// </param>
    override public void Run(GameObject obj, ActionData data)
    {
        if (startObject == null)
        {
            GameObject intersectedObj = PickUtil.GetObjectUnderMouseRay();
            if (intersectedObj != null)
            {
                startObject = intersectedObj.GetComponent <Rigidbody>();
                if (startObject != null)
                {
                    float hitT;
                    anchor = PickUtil.GetXYPlaneHitPoint(out hitT) - intersectedObj.transform.position;
                }
            }
        }
        else
        {
            GameObject obj2 = PickUtil.GetObjectUnderMouseRay();
            if (obj2 != null && obj2 != startObject)
            {
                Rigidbody body2 = obj2.GetComponent <Rigidbody>();
                if (body2 != null)
                {
                    float   hitT;
                    Vector3 anchor2 = PickUtil.GetXYPlaneHitPoint(out hitT) - obj2.transform.position;

                    SpringJoint joint = startObject.gameObject.AddComponent <SpringJoint>();
                    joint.anchor          = anchor;
                    joint.connectedBody   = body2;
                    joint.connectedAnchor = anchor2;
                }
            }
        }
    }
Example #2
0
    /// <summary>
    /// Returns the shooting direction.
    /// </summary>
    /// <param name='obj'>
    /// Object.
    /// </param>
    override protected Vector3 GetDirection(GameObject obj, ActionData data)
    {
        float   hitT;
        Vector3 mousePos = data.mousePos == Vector3.zero ?
                           PickUtil.GetXYPlaneHitPoint(out hitT) : data.mousePos;
        Vector3 direction = mousePos - obj.transform.position;

        direction.Normalize();
        return(direction);
    }
Example #3
0
    /// <summary>
    /// Returns the position for the shot to start at.
    /// </summary>
    override protected Vector3 GetPosition(GameObject obj, Vector3 shotDirection, ActionData data)
    {
        float   hitT;
        Vector3 pos = PickUtil.GetXYPlaneHitPoint(out hitT);

        if (tileSize > 0)
        {
            pos = new Vector3((int)(pos.x / tileSize) * tileSize, (int)(pos.y / tileSize) * tileSize, 0);
        }
        return(pos);
    }