Solve Acute Angle Problem in 2D Sim/Game

  • Thread starter Thread starter sciwizeh
  • Start date Start date
  • Tags Tags
    Turning
AI Thread Summary
The discussion centers on a challenge in a 2D simulation game where circles representing people navigate a city with walls and barriers. The main issue arises when two line segments intersect at an acute angle, causing the circles to move directly through the intersection instead of turning. The user has attempted to adjust the velocity to avoid walls but found that removing a specific adjustment made the motion too erratic. They are considering implementing A* pathfinding for better navigation around obstacles while still seeking advice on wall avoidance techniques. The goal is to achieve smoother movement while effectively avoiding barriers.
sciwizeh
Messages
25
Reaction score
0
So, I'm working on a 2D sim/game in which "people" aka circles travel around a "city" aka plane with boxes and line barriers. In the person step I'm passing a list of line segments, consisting of walls boundaries etc. and I'm having a bit of trouble when two lines meet at an acute angle. When the person heads toward the intersection point, it's velocity bisects the angle and goes directly through. I'm at a loss to how I should make the person turn around. My current stepping function follows, I'm probably not going about this in the most optimal way, but with the exception of the problem mentioned it works well.

the code is in Java, however it should not be difficult to interpret by people familiar with other languages.
Code:
public void step(double dt, ArrayList<Line> lines){
	for(Line l : lines){
		double dist = l.distance(loc);//gets distance from the point to the segment
		if(dist<(rad*LINE_DIST)) {//consider the segment only if we are close
			double dot = l.getVec().dot(vel);//segmentVector*velocity
			double sig = (dot<0) ? -1 : 1;//sign of the dot product
			Vector des =  l.getVec().mul(sig);//velocity that would be parallel 
			Vector steer = des.diff(vel);//vector to transform velocity to dest
			steer.normalize();//just the direction of steer kept
			vel.add(steer.mul(LINE_ADVERSION));//transform velocity to dest frame by frame
			Vector toP1 = loc.diff(l.p1);//vector from the first point of the segment to the location
			sig = (l.getNormal().dot(toP1)<0) ? -1 : 1;//side of the segment point is on
			vel.add(l.getNormal().mul(sig));//adjustment of velocity keeps right angles from causing current acute angle problem
		}
	}
//	vel.noise();//this was the original fix for right angle
	vel.limit(50);//speed limit
	loc.add(vel.mul(dt));//location update
		
}

any help would be appreciated. as I said, I know my method is sloppy at best, but I'm really at a loss.

EDIT: after more testing and commenting out the line vel.add(steer.mul(LINE_ADVERSION)); the acute problem is solved, and it does avoid the lines, but the motion is much too bouncy, like a spring, and it doesn't follow the line at all, which I do like. so i could still use some information if possible
 
Last edited:
Physics news on Phys.org
Well, as I can't edit anymore, I'm double posting and bumping because I've decided to automatically generate a graph and go just use A* to find paths. Looking at my intended end result, I really do need path finding that will go around things, so this is likely the best way for my project.
I'm still curious how I might do this with just wall avoidance, so any advice would still be appreciated.
 
Back
Top