Hello everyone! Im trying to create an object that as soon as the script is run each 2 seconds it will get the position of a GameObject (in this case “Player”). and move towards that position at a certain speed.
If you guys could help me out, I’ve only got this:
public class movementScript : MonoBehaviour {
public float speed = 2.5f;
private PlayerController player;
public Vector3 playerPosition;
// Use this for initialization
void Start ()
{
player = GameObject.Find ("Player").GetComponent<PlayerController>();
}
void CheckForPlayerMovement {
//get Player's Position
player.position = playerPosition;
//Move toward that position
transform.translate (playerPosition * speed * Time.deltaTime);
//I need your help here to do the proper cast of what I want to do,
//which is move towards playerPosition at a certain speed.
}
I also need help with what would be the best practice to call that function at a certain time.(If possible from object creation).
Thanks for your time