Hi guys
I am have trouble checking if a gameobeject is at a specific location to make this easier to explain I have made a couple of videos
This video shows what happens when I check the stopPosition
This video shows what happens when I don’t check the stopPosition
This The code I use to move the enemys to their stopPositions
if (direction == shipDirection.up) //******************************* Move Enemys UP
{
gameSpeed += gameController.theScrollSpeed * Time.deltaTime;
setStopPosition();
stopPosition = stopY;
stopPosition = new Vector3(stopY.x + deployRate, stopY.y, stopY.z);
transform.position = Vector3.MoveTowards(transform.position, stopPosition, shipSpeed * Time.deltaTime);
CheckStopPosition();
}
if (direction == shipDirection.down) //******************************** Move Enemys DOWN
{
setStopPosition();
stopPosition = new Vector3(stopY.x + deployRate, -stopY.y, stopY.z);
transform.position = Vector3.MoveTowards(transform.position,stopPosition, shipSpeed * Time.deltaTime);
CheckStopPosition();
}
This is code I use to check if the enemys are at their stopPositions so that I can get them to hold their positions whilst the camera is scrolling
void CheckStopPosition()
{
float dist = Vector3.Distance(firstStop, transform.position);
if (transform.position == stopPosition)
{
Debug.Log("we are at stop " + transform.position);
Debug.Log("We should of stopped at " + stopPosition);
Debug.Log(dist);
direction = shipDirection.stop;
//transform.position = new Vector3(transform.position.x + gameController.theScrollSpeed * Time.deltaTime, transform.position.y);
}
if (direction == shipDirection.stop) //************************************** STOP
{
if (otherCheckOnce == false)
{
Debug.Log("I have stopped at " + transform.position); // This is only so we get one output of debug.log and not 1 every frame
otherCheckOnce = true;
}
//this holds the enemy position relitave to the camera
//
transform.position = new Vector3(transform.position.x + gameController.theScrollSpeed * Time.deltaTime, transform.position.y);
}
I want the enemys to stop in a straight line like in the second video but hold that position whilst the camera is scrolling