Shooting Arrow Issue

I’ve been trying to work on this issue for a while now, and this is about the closest I’ve come but it’s still not right yet.

I’ve instantiated an arrow, normalized it because the arrows were way off target. However, even after normalizing the target vector it still seems noticeably off… Also, when I factor in deltaTime into the velocity it slows my velocity down to almost a halt no matter how high I set the projectileSpeed.

Can anyone help me with figuring out how to make the arrow move/land more accurately at a proper speed using deltaTime?

(I’ve tinkered with MovePosition, MoveTowards, etc…and this seems like I have the best outcome so far with using velocity).

Thanks in advance…

    void Target(Vector2 target){
        Debug.Log(target);
        GameObject arrow = Instantiate(projectilePrefab, transform.position, Quaternion.identity);
        target.Normalize();
        Debug.Log(target);
        arrow.GetComponent<Rigidbody2D>().velocity = target * (projectileSpeed * Time.deltaTime);
        Destroy(arrow, 3.0f);
    }

Hi @heytheremogwai

Well at least this is your problem:

arrow.GetComponent<Rigidbody2D>().velocity = target * (projectileSpeed * Time.deltaTime);

You are setting velocity, which is not a step per frame, but a value per second… so don’t multiply it with deltatime.

And usually, to get more help, it is better to explain what exactly you are doing. Show an image, explain what kind of objects you are using and so. Now there are many unknowns.

@heytheremogwai

About arrows landing where user clicked not working…

You didn’t even share the code, how do you convert your mouse position into world position and so on…?

Could just simply edit you original post, instead of adding one detail at time perhaps?