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); }
public float GetForce(ForceController2D entity) { switch (fieldType) { case FieldValueType.Accel: return(entity.body.mass * fieldValue); case FieldValueType.Force: return(fieldValue); default: return(0f); } }
public override Vector2 GetDir(ForceController2D entity) { return(dir); }
public virtual void ItemRemoved(ForceController2D ctrl) { }
public abstract Vector2 GetDir(ForceController2D entity);