Why are bullets missing?

Here’s a picture of what’s happening during runtime. Imgur: The magic of the Internet
Here’s my relevant section of code. This script is going on the bullet itself. Basically, when the bullet is instantiated, this script tells it where to fly.

    void Start()
    {
        BulletDir = DestinationPos - transform.position;
        Debug.DrawRay(transform.position, BulletDir, Color.yellow, 99999999, false);
    }

    void Update()
    {
        transform.Translate(BulletDir * BulletSpeed * Time.deltaTime);
    }

I’m sure this is just a stupid mistake on my part, but I believe I’m doing this correctly. The REALLY strange thing to me is that the debug ray is going EXACTLY where it should be going, on top of the big rectangular box. But the bullets, using the exact same destination, and the exact same method of calculating the direction vector, are going off to the right. Like if my math was wrong, you’d think the bullets would be going wildly in the wrong direction, but they’re only slightly off. I’m just confused. Any ideas?

By default, Translate works in local space, but the bullet direction is world-space.

This will cause the bullet to move in the wrong direction if it has been rotated (and the more rotated it is, the more incorrect the movement will be). If it’s been turned 90 degrees to the right, for example, the bullet’s “forward” direction will be the world’s “right” direction.

I’d just add to transform.posiiton. Alternatively, you could pass Space.World as second argument.

1 Like

Thanks so much! I knew it would be something simple I was ignorant of. Changed to world.space and it worked immediately. You’re awesome thanks!