I have 2D project, where placed two Sprite. First moving to position of Touch on screen. Second moving to position of First. All movements are done through transform.position
The essence of problem: Second moves as it should, but not First.
Firstly: I fix the Z-axis, because on Touch object travels far away on Z-axis (this happens also if i’m using mouse.position instead of touch.position)
Second:self movement:
Touch touch = Input.GetTouch(0);
Vector3 touchpos = cam.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 0f));
touchpos.Normalize();
float moveposX = touchpos.x * speed * Time.fixedDeltaTime;
float moveposY = touchpos.y * speed * Time.fixedDeltaTime;
PlayerObj.transform.position = PlayerObj.transform.position + new Vector3(moveposX, moveposY,0f);
Movement too slow compare to Second object, which travel to First, has the same speed and which has code:
Vector3 delta = transform.position - Player.position;
delta.Normalize();
if (Vector2.Distance(transform.position, Player.transform.position) < Distance && Catch.CurrentCatch == "Enemy")
{
Enemy.transform.position += -delta * Speed * Time.fixedDeltaTime;
}
else
{
Enemy.transform.position += delta * Speed * Time.fixedDeltaTime;
}
If use Input.GetAxis, than control works as it should - both object has same speed.
How i can solve first problem - do not fix Z-axis and second problem - speed of controllable object?
Sorry for my english