Solve Acute Angle Problem in 2D Sim/Game

  • Thread starter Thread starter sciwizeh
  • Start date Start date
  • Tags Tags
    Turning
Click For Summary
SUMMARY

The discussion focuses on solving the acute angle problem in a 2D simulation game where circles navigate a plane with line barriers. The user implements a Java function to adjust the velocity of circles when they approach line segments, but encounters issues with motion being overly bouncy and not following the lines accurately. After testing, the user finds that commenting out a specific line of code resolves the acute angle issue but introduces undesired bounciness. The user is considering using A* pathfinding for better navigation around obstacles while still seeking advice on wall avoidance techniques.

PREREQUISITES
  • Understanding of 2D vector mathematics
  • Familiarity with Java programming
  • Knowledge of basic game physics and collision detection
  • Experience with pathfinding algorithms, specifically A*
NEXT STEPS
  • Research "Java vector mathematics for game development"
  • Explore "Implementing A* pathfinding in Java"
  • Study "Collision avoidance techniques in 2D games"
  • Investigate "Optimizing velocity adjustments in game physics"
USEFUL FOR

Game developers, particularly those working on 2D simulations, programmers seeking to improve navigation algorithms, and anyone interested in collision detection and avoidance strategies in gaming contexts.

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.
 

Similar threads

  • · Replies 21 ·
Replies
21
Views
1K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
13K