public override Vector2 GetDir(ForceController2D entity)
        {
            Vector2 position = entity.transform.position;
            Vector2 center   = transform.position;

            Vector2 dir = inward ? center - position : position - center;

            return(dir.normalized);
        }
        public override Vector2 GetDir(ForceController2D entity)
        {
            Vector2 center = this.center ? this.center.position : transform.position;

            Vector2 toDir;

            Vector2 entPos = entity.transform.position;
            Vector2 entUp  = entity.transform.up;

            Vector2 dir = checkDirInverse ? entPos - center : center - entPos;

            dir.Normalize();

            //check if we are within reasonable angle between entity's up and dir from center
            //if(Vector3.Angle(dir, entUp) < checkEntityAngle) {
            //check downward and see if we collide

            Vector2 checkDir = checkUseEntityUp ? -entUp : -dir;

            RaycastHit2D hit;

            if (checkRadius > 0f)
            {
                hit = Physics2D.CircleCast(entPos, checkRadius, checkDir, checkDistance, checkLayer);
            }
            else
            {
                hit = Physics2D.Raycast(entPos, checkDir, checkDistance, checkLayer);
            }

            if (hit.collider)
            {
                if (Vector2.Angle(dir, hit.normal) < checkSurfaceAngle && Vector2.Angle(entUp, hit.normal) > dirAngleChangeThreshold)
                {
                    toDir = hit.normal;
                }
                else
                {
                    toDir = entUp;
                }
            }
            else
            {
                toDir = entUp;
            }
            //}

            //var toDir = info != null ? info.curDir : entUp;

            return(dirInverse ? -toDir : toDir);
        }
Esempio n. 3
0
        public float GetForce(ForceController2D entity)
        {
            switch (fieldType)
            {
            case FieldValueType.Accel:
                return(entity.body.mass * fieldValue);

            case FieldValueType.Force:
                return(fieldValue);

            default:
                return(0f);
            }
        }
Esempio n. 4
0
 public override Vector2 GetDir(ForceController2D entity)
 {
     return(dir);
 }
Esempio n. 5
0
 public virtual void ItemRemoved(ForceController2D ctrl)
 {
 }
Esempio n. 6
0
 public abstract Vector2 GetDir(ForceController2D entity);