15,936,265 members
See more:
So I'm making an ai for a tank game but instead of the tank moving smoothly, it just skids around in one direction when it should be moving around the map independently as well. how do I fix this? Here is the code:
C#
```using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyTankMove : MonoBehaviour
{
Rigidbody rbEnemyTank;

float posX;
float posZ;

float posMin = 50f;
float posMax = 50f;

Vector3 targetPos;

public float speedMove = 0.05f;
public float speedRotate = 0.1f;

void Awake()
{
rbEnemyTank = GetComponent<rigidbody>();
}

void Start()
{
GetNewPosition();
}

void GetNewPosition()
{
posX = Random.Range(posMin, posMax);
posZ = Random.Range(posMin, posMax);

Vector3 newPosition = new Vector3(posX, transform.position.y, posZ);
targetPos = newPosition;
}

void Update()
{
if (Vector3.Distance(transform.position, targetPos) < 10f)
{
GetNewPosition();
}
Rotate();
}

void FixedUpdate()
{
Move();
}

void Rotate()
{
Vector3 tankDir = targetPos - transform.position;
float step = speedRotate * Time.deltaTime;
Vector3 newDir = Vector3.RotateTowards(transform.forward, tankDir, step, 0.0f);
}

void Move()
{
Vector3 moveForward = transform.forward * speedMove;
rbEnemyTank.MovePosition(rbEnemyTank.position + moveForward);
}
}```

What I have tried:

nothing has worked, I need help but as I'm new to programming please be understanding.

Thanks!
Posted
Updated 1-Feb-21 3:32am
v2

## Solution 1

When your minimum and maximum are both the same, how do you expect to get any "range"?
```float posMin = 50f;
float posMax = 50f;```