Answer the question
In order to leave comments, you need to log in
How to move an object by x position?
Hello! I have a script where if an enemy comes close to the player it stops and should move x but it freezes. Also, if I put not transform but Target, he just teleports to him
public Transform Target;
public int speed;
void Start()
{
Target = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update()
{
if (transform.position.y < -3)
{
transform.position = Vector2.MoveTowards(transform.position, Target.position, speed * Time.deltaTime);
}
else
{
transform.position = Vector2.MoveTowards(Target.position, transform.position, speed * Time.deltaTime);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question