Example #1
0
 void moveToSurfaceCoord(SurfaceCoords pos)
 {
     _lastPos    = _curPos;
     _curPos     = pos;
     _updateFlag = true;
     _lastNormal = Vector2.right.Rotate(_curPos.normalDegrees);
 }
Example #2
0
 public void ResetToolSettings()
 {
     maxBrushRadius          = 20.0f;
     maxBrushSpacing         = 5.0f;
     surfaceCoords           = SurfaceCoords.AroundX;
     hideSceneSettingsObject = true;
     groupName                  = "_group";
     gridRaycastHeight          = 5.0f;
     uiColor                    = new Color(1, 0, 0, 1);
     useAdditionalVertexStreams = false;
 }
        public void SnapTo(Rigidbody2D target, Vector2 pos, Vector2 normal)
        {
            if (_target != null) Unsnap();

            enabled = true;
            _target = target;

            _curPos = worldCoordsToSurfaceCoords(pos, normal);
            _lastPos = _curPos;
            _updateFlag = true;
        }
Example #4
0
    public void SnapTo(Rigidbody2D target, Vector2 pos, Vector2 normal)
    {
        if (_target != null)
        {
            Unsnap();
        }

        enabled = true;
        _target = target;

        _curPos     = worldCoordsToSurfaceCoords(pos, normal);
        _lastNormal = Vector2.right.Rotate(_curPos.normalDegrees);
        _lastPos    = _curPos;
        _updateFlag = true;
    }
Example #5
0
    public void SnapTo(Collider2D target, Rigidbody2D rb, Vector2 pos, Vector2 normal, Vector2 initialVelEstimate)
    {
        if (_target != null) Unsnap(false);

        enabled = true;

        _target = target;
        _targetBody = rb;

        _velocityEstimate = initialVelEstimate;
        _curPos = worldCoordsToSurfaceCoords(pos, normal);
        _curWorldPos = pos;
        _lastWorldPos = _curWorldPos;
        _lastPos = _curPos;
        _updateFlag = true;
        _justSnapped = true;
    }
Example #6
0
    public void SnapTo(Collider2D target, Rigidbody2D rb, Vector2 pos, Vector2 normal, Vector2 initialVelEstimate)
    {
        if (_target != null)
        {
            Unsnap(false);
        }

        enabled = true;

        _target     = target;
        _targetBody = rb;

        _velocityEstimate = initialVelEstimate;
        _curPos           = worldCoordsToSurfaceCoords(pos, normal);
        _curWorldPos      = pos;
        _lastWorldPos     = _curWorldPos;
        _lastPos          = _curPos;
        _updateFlag       = true;
        _justSnapped      = true;
    }
Example #7
0
    void FixedUpdate()
    {
        _curWorldPos      = surfaceCoordsToWorldCoords(_curPos);
        _velocityEstimate = _curWorldPos - _lastWorldPos;
        _lastWorldPos     = _curWorldPos;

        if (_updateFlag)
        {
            _updateFlag = false;
        }
        else
        {
            _lastPos = _curPos;
        }

        if (_target != null)
        {
            _target.gameObject.SendMessage("StayOn", null, SendMessageOptions.DontRequireReceiver);
        }
    }
Example #8
0
    Vector2 surfaceCoordsToWorldCoords(SurfaceCoords s)
    {
        var targetObject = _targetBody ? _targetBody.gameObject : _target.gameObject;

        var theta = (targetObject.transform.rotation.eulerAngles.z + s.degrees) * Mathf.Deg2Rad;
        return Vector2Ext.FromPolar(s.radius, theta) + targetObject.transform.position.AsVector2();
    }
Example #9
0
 void moveToSurfaceCoord(SurfaceCoords pos)
 {
     _lastPos = _curPos;
     _curPos = pos;
     _updateFlag = true;
 }
Example #10
0
    void FixedUpdate()
    {
        _justSnapped = false;

        dbg = _targetBody.name;

        _curWorldPos = surfaceCoordsToWorldCoords(_curPos);
        _velocityEstimate = _curWorldPos - _lastWorldPos;
        _lastWorldPos = _curWorldPos;

        if (_updateFlag) _updateFlag = false;
        else _lastPos = _curPos;

        if (_target != null) {
            _target.gameObject.SendMessage("StayOn", null, SendMessageOptions.DontRequireReceiver);
        }
    }
Example #11
0
    SnapResult linecastAndSnap(Vector2 p0, Vector2 p1, Vector2 offset)
    {
        var hitsPrime = Physics2D.LinecastAll(p0, p1, MooseController.CollisionLayerMask);
        var hitsDos   = new List <RaycastHit2D>();

        for (var i = 0; i < hitsPrime.Length; ++i)
        {
            if (_targetBody)
            {
                if (hitsPrime[i].rigidbody == _targetBody)
                {
                    hitsDos.Add(hitsPrime[i]);
                }
            }
            else
            {
                if (hitsPrime[i].collider == _target)
                {
                    hitsDos.Add(hitsPrime[i]);
                }
            }
        }
        if (hitsDos.Count == 0)
        {
            return new SnapResult {
                       success = false
            }
        }
        ;
        var hit = hitsDos[0];

        return(new SnapResult {
            success = true,
            newPos = worldCoordsToSurfaceCoords(hit.point + offset, hit.normal),
            normal = hit.normal
        });
    }

    bool maybeMoveToSnap(SnapResult snap, Func <Vector2, bool> normalCheck)
    {
        if (!snap.success || !normalCheck(snap.normal))
        {
            return(false);
        }
        moveToSurfaceCoord(snap.newPos);
        return(true);
    }

    void moveToSurfaceCoord(SurfaceCoords pos)
    {
        _lastPos    = _curPos;
        _curPos     = pos;
        _updateFlag = true;
    }

    Vector2 surfaceCoordsToWorldCoords(SurfaceCoords s)
    {
        var targetObject = _targetBody ? _targetBody.gameObject : _target.gameObject;

        var theta = (targetObject.transform.rotation.eulerAngles.z + s.degrees) * Mathf.Deg2Rad;

        return(Vector2Ext.FromPolar(s.radius, theta) + targetObject.transform.position.AsVector2());
    }

    SurfaceCoords worldCoordsToSurfaceCoords(Vector2 pos, Vector2 normal)
    {
        var ds          = pos - (_targetBody ? _targetBody.position : _target.transform.position.AsVector2());
        var angleOffset = _targetBody ? _targetBody.rotation : _target.transform.rotation.z;

        return(new SurfaceCoords {
            radius = ds.magnitude,
            degrees = Mathf.Atan2(ds.y, ds.x) * Mathf.Rad2Deg - angleOffset,
            normalDegrees = Mathf.Atan2(normal.y, normal.x) * Mathf.Rad2Deg - angleOffset
        });
    }
}
        void FixedUpdate()
        {
            _curWorldPos = surfaceCoordsToWorldCoords(_curPos);
            _velocityEstimate = _curWorldPos - _lastWorldPos;
            _lastWorldPos = _curWorldPos;

            if (_updateFlag) _updateFlag = false;
            else _lastPos = _curPos;
        }
Example #13
0
 void moveToSurfaceCoord(SurfaceCoords pos)
 {
     _lastPos = _curPos;
     _curPos = pos;
     _updateFlag = true;
     _lastNormal = Vector2.right.Rotate(_curPos.normalDegrees);
 }
Example #14
0
    Vector2 surfaceCoordsToWorldCoords(SurfaceCoords s)
    {
        var theta = (_target.gameObject.transform.rotation.eulerAngles.z + s.degrees) * Mathf.Deg2Rad;

        return(Vector2Ext.FromPolar(s.radius, theta) + _target.transform.position.AsVector2());
    }