In order to create a new type of movement behavior for the tank first start by creating a new script under the folder Tank>Movement>InputActionTypes
Name the script describing the type of tank movement behavior you want to implement like this
Use the IInputActionController interface to choose the actions your new tank behavior would like to implement and those are
public interface IInputActionController
{
IInputActionController Up(Action onUp);
IInputActionController Down(Action onDown);
IInputActionController Left(Action onLeft);
IInputActionController Right(Action onRight);
IInputActionController Fire(Action onFire);
IInputActionController VerticalMovementFinish(Action onVerticalMovementFinish);
IInputActionController HorizontalMovementFinish(Action onHorizontalMovementFinish);
}
Example for RandomInputActions implementation using the interface IInputActionController
public IInputActionController Up(Action onUp)
{
Update();
if (moveDirection==0)
onUp();
return this;
}
Finally, add the desired direction in an Update method that will execute the tank movement behavior as desired when the script is called upon like this
private void Update()
{
CountDown -= Time.deltaTime;
if (CountDown <= 0)
{
moveDirection = UnityEngine.Random.Range(0, 4);
CountDown = maxTime;
}
}
The required variables for this exercise were
private int moveDirection = 0;
private float maxTime = 5f;
private float CountDown;
Tank Jerking
Actual behavior: the tank is jerking back and forth every time the opposite direction is tapped
Expected behavior: the tank does not jerk when any buttons are pressed at the same time. When a new movement direction is inputted the tank needs to start to move in the latest input direction and ignore all other previous inputs.
Game Design/Technical comment: the tank position rounding is expected only when the tank changes direction under an angle of 90° in any direction other than the direction it is currently moving. Because the only time the tank object needs to adapt its position according to the rails is when it’s changing direction at an angle of 90°.
Power-Ups Spawn Half Out of Bounds
Actual: The power-up spawns half out of the bounds of the map
Expected: The power-up can only spawn fully within the bounds of the map
Power-Ups Spawn On Top of The Player Tank
Actual: The power-up spawns on top of the player's tank and causes unexpected behavior for the player
Expected: The power-up can not spawn on top of the player tank, only at a distance of 4 environment tiles
Power-Ups Spawn On Top of Eagle
Actual: The power-up spawns on top of the eagle
Expected: The power-up can not spawn on top of the eagle
Enemy Tanks Spawn on top of Each-Other
Actual behavior: The spawning tank is physically moving the active tank when it appears on the screen.
Expected behavior: When the spawn point is physically taken by an active tank, the spawn point should be activated elsewhere
Game Design/Technical comment: The spawn point should be prompted` in a location where there is no active tank