I’m working on a script to cast magic orbs, they instantiate as I would like, and start to move in the desired direction, but they only move a tiny amount before they snap back to their spawnpoint and they just repeat like this. I have used the same line to move used here as I have in another script which moves a different object exactly as I would like. Can anyone see what I am doing wrong?
public class MagicOrb : MonoBehaviour
{
Vector2 orbTarget;
Vector2 currentPos;
public float orbSpeed;
public GameObject player;
Rigidbody2D rb;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
currentPos = rb.transform.position;
var mousePos = Input.mousePosition;
mousePos.z = 10;
orbTarget = Camera.main.ScreenToWorldPoint(mousePos);
}
private void Update()
{
rb.MovePosition(Vector2.MoveTowards(currentPos, orbTarget, orbSpeed * Time.deltaTime));
}
}