# 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:

MoveTowardsTarget()

RotateTowardsTargetDirection()

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;
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){
MoveTowardsTarget(_targetPosition);
}

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