Hello folks!
So I have this problem where I am blocked with a code, the code in question allows my character to shoot a fireball at the place where I click with my mouse, but, instead of doing that, the fireball goes to the place where the camera is, (the camera is not moving, only the character),
I thinks it is a problem with Instantiate and the mousePos, any of you know how I can resolve this issue?
here is the code:
void Update()
{
if (Input.GetMouseButtonDown(0))
{
GameObject sort = Instantiate(projectile, transform.position,
Quaternion.identity);
Vector2 mousePos =
Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 myPos = transform.position;
Vector2 direction = (mousePos - myPos).normalized;
sort.GetComponent<Rigidbody2D>().velocity = direction *
vittProjectile;
}
}
To maje this code I’ve watch this tutoriel on how to make a rougue like:
Hope someone will be able to help me ^^
Hello if "the fireball goes to the place where the camera is" is because you are misscalculating the vector.
– tormentoarmagedoom