roads now go straight if they have the option to do so -> merges look right
1 parent bb9c459 commit a05fdb2dbff9e228a074aa294fea49ac607f6c5e
@biosfood biosfood authored on 4 Mar 2022
Showing 2 changed files
View
2
■■■
.gitignore
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
.vscode
 
Assets/Scripts/*.meta
/Assets/Scripts/*.meta
View
30
Assets/Scripts/Roads/Node/Node.cs
 
abstract public void pull(Vector3 position);
 
private void updateDirection() {
Vector3 inDirection = getAverageDirection(roads.FindAll(it => it.nodes[0] == this), 0);
Vector3 outDirection = getAverageDirection(roads.FindAll(it => it.nodes[1] == this), 1);
List<Road> incomingRoads = roads.FindAll(it => it.nodes[0] == this);
List<Road> outgoingRoads = roads.FindAll(it => it.nodes[1] == this);
Vector3 inDirection = getAverageDirection(incomingRoads, 0, outgoingRoads);
Vector3 outDirection = getAverageDirection(outgoingRoads, 1, incomingRoads);
direction = (inDirection - outDirection) * 0.25f;
}
 
public void lateUpdate(Road caller) {
road.update(true);
}
}
 
private Vector3 getAverageDirection(List<Road> roads, int index) {
private Vector3 getAverageDirection(List<Road> roads, int index, List<Road> otherRoads) {
Vector3 sum = new Vector3(0f, 0f, 0f);
if (roads.Count == 0) {
return sum;
}
foreach (Road road in roads) {
sum += road.nodes[1-index].position - position;
Vector3 direction = road.nodes[1-index].position - position;
sum += direction;
direction.Normalize();
foreach (Road otherRoad in otherRoads) {
Vector3 otherDirection = otherRoad.nodes[index].position - position;
otherDirection.Normalize();
if ((direction + otherDirection).magnitude < 0.1f) {
return direction * (otherRoad.nodes[index].position - road.nodes[1-index].position).magnitude / 4f;
}
}
}
return sum / roads.Count;
}