예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #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);
            }
        }
예제 #4
0
 public override Vector2 GetDir(ForceController2D entity)
 {
     return(dir);
 }
예제 #5
0
 public virtual void ItemRemoved(ForceController2D ctrl)
 {
 }
예제 #6
0
 public abstract Vector2 GetDir(ForceController2D entity);