Strategies for Physics-based Movement for 2D Space RTS Controls?

Heya, I’ve been hammering out this problem for awhile, and I think I’ve reached a dead-end.

I’m trying to create a simple DC/RTS controller capable of steering a physics-controlled Spaceship to a target position & heading.

I’ve got the following two basic functions working:



Both use Rigidbody2D.Addforce / AddTorque and calculate braking force per-frame in order to accelerate/slow the ship correctly.

Currently I’m just running both update functions simultaneously until the ship reaches the target position. Unfortunately, this means that if I give the ship a target location behind it and relatively close to it, the ship can never reach the target position, and instead orbits it.

I’m aware this code has problems, but I’m not sure what kind of “Crossover” algorithm I need to determine if the target location is too close to the ship to move-while-turning, based off of the turn-speed and movement speed of a specific ship.

void UpdateMoveToPosition()
		if(_moveTargetReached == false)
			//Grab the Clicked position, set it's Z axis to match the same plane as the ship, then calculate relevant information.
			Vector3 CursorPosition = _targetPosition;
			CursorPosition.z = transform.position.z;
			Vector3 targetDir = CursorPosition - transform.position;
			bool TargetAhead = true;
			float AngleOffsetFromForward = Vector2.Angle (transform.up,targetDir);
			float DistanceRemaining = Vector3.Distance (transform.position,CursorPosition);

			if(AngleOffsetFromForward > 90 ){TargetAhead = false;}

			//If we're outside our margin of error for Heading and distance, then set our turnTarget to false.
			//This enables the update loop: RotateTowardsTargetDirection(). 
			if(AngleOffsetFromForward > 2f && DistanceRemaining > 10f && _turnTargetReached == true)
				_turnTargetReached = false;
			//Once TurnTargetReached is false, it must be set true again in the "RotateTowardsTargetDirection" function. 
			if(_turnTargetReached == false)
				RotateTowardsTargetDirection (targetDir);

			//Likewise, MoveTargetReached is false until we reach the target position.
			//This is where the logical flaw is. This Function only updates the ship along its own forward-facing axis. Right now, it updates regardless of the status of TurnTargetReached.
			if(_moveTargetReached == false){

			//Once the move target is reached, set the final heading of the ship, then abort this update loop.
			if(_moveTargetReached == true)
				_finalHeading = transform.up;

The difficulty of the problem is compounded since both MoveTowardsTarget and RotateTowardsTargetDirection actually use forces to update the movement of the ship, and calculate braking force in order to slow/stop it. (Making them difficult to plug into, and temperamental due to the mismatches between simulated braking distance & the physics engine.)

Any advice or links to something I could read-up on to better understand the kind of algorithm / code that would be needed to make a true algorithm would be a life-saver. I’d hate to give up on true physics-based movement for the game, but I’m running out of ideas on how to make this function properly.

I would look into something like a PID controller. That way it will be able to adjust the values based on the predicted error.
If you want to read up on it: PID controller - Wikipedia

I am currently in the process of programming one myself so I can’t make specific recommendations as of yet about how to go about it. You may want to go search up a guide on how to go about programming it if you have difficulty understanding the calculations.