- Home /
trying to make a projectile move towards mouse position but but im getting an error anyone able to help
Assets\Scripts\PlayerProjectile.cs(18,38): error CS7036: There is no argument given that corresponds to the required formal parameter 'maxDistanceDelta' of 'Vector2.MoveTowards(Vector2, Vector2, float)
so thats the error i get and idk why MoveTowards is under lined with red also this is a 2D game if you couldnt already tell by the vector2 any help would be nice
Answer by sean244 · Jan 21, 2019 at 03:29 AM
First off, you should set target in Update, not in Start, because the mouse position is constantly changing.
Second, you have to re-write
transform.position = Vector2.MoveTowards(transform.position, speed * Time.deltaTime);
to
transform.position = Vector2.MoveTowards(transform.position, target, speed * Time.deltaTime);
just quickly wanted to say if you put target in update it actually will cause the bullets to follow the mouse position around until they reach the mouses position. by putting it in start it will make the projectiles go to the mouses last position. if that makes sense im not very good at explaining stuff hehe but anyways once again thanks.
Ah, ok. If that's what you want, then I guess it should be in Start after all. $$anonymous$$y mistake.
well i guess you could in away use it to make a projectile you control in a 2D game. so no mistakes Sean only more ideas