3d Isometric Shooter

I’m trying to figure out how to get a projectile to translate in a forward motion from the players gun to the mouse position clicked. Ive managed to find how to get the mouse position. But every time I replace translate(vector3.forward) to translate(mousePosition) the gun stops shooting anything

public class Bullet : MonoBehaviour
{

    public float speed;
    public float maxDistance;

    private Camera RefMainCamera;

    public Vector3 MousePos;
    private Plane ZeroYPlane;

    private void Start()
    {
        RefMainCamera = Camera.main;
        ZeroYPlane = new Plane(Vector3.up, Vector3.zero);
    }

    // Update is called once per frame
    void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);


        float _hitDistance;
        //cast ray using zerpYplane to find out mouse position the ray intersects it
        ZeroYPlane.Raycast(ray, out _hitDistance);
        Vector3 MousePosition = ray.GetPoint(_hitDistance);

        transform.Translate(Vector3.forward * Time.deltaTime * speed);
        maxDistance += 1 * Time.deltaTime;

        if(maxDistance >= 5)
        {
            Destroy(this.gameObject);
        }
    }
}

First up, “General Discussion” is not a support area. You should post stuff in the correct place.

That aside…

That’s because “forward” is a direction, where “mousePosition” is a position. They’re both represented as Vector3s, but they mean different things in different contexts. To fully understand this you’ll need to learn some vector math.

To find the direction and distance between two positions you can subtract one from the other. (destination - origin) gives you a vector which goes from origin to destination. Because it’s being used as a direction you probably need to “normalize” it. This makes its length = 1.0f, which is useful in lots of situations. (In this case, different lengths would interfere with the resulting speed of the moving object.)

In code that looks something like:

Vector3 dir = (destination - origin).normalized;

Learning about stuff you can do with vectors will also help you sort out what’s happening with your maxDistance, there.

Edit: The Learn section covers this stuff, so you should check that out.