So I am a total beginner in coding. I am trying to get my Pong AI to work and I am using the Vector3.MoveTowards.
I have searched for people with similar problems but often I don’t understand the answers given. Or the answer is given in Java and I don’t know how to convert it to c#.
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
Transform Ball;
public float speed = 10;
float movey;
void Start()
{
Ball = GameObject.FindGameObjectWithTag ("Ball").transform;
}
// Update is called once per frame
void Update ()
{
Vector3 giPos = Ball.transform.position;
giPos.y = movey;
Ball.transform.position = giPos;
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, movey, step);
}
}
Anyway, this is my code so far. It returns an compiler error in unity saying:
CS1502: The best overloaded method match for UnityEngine.Vector3.MoveTowards(UnityEngine.Vector3, UnityEngine.Vector3, float)' has some invalid arguments And also: CS1503: Argument
#2’ cannot convert float' expression to type
UnityEngine.Vector3’
I understand that the “movey” thing is what is causing the error but I am at a complete loss on how to fix it. I feel stupid for asking but I’m banging my head against the wall. Feels like I have tried everything.