As long as your subnet where the VPN Gateway has been configured and your Subnet(s) where your are VM are located are in the same VNet, it should work. Make sure your NSG rules and the OS firewall allow the communication.
Then depending how you will establish VPN connection you will have few more steps to configure the P2S VPN:
Please also be aware that you have another option to connect to your VM securely by using Azure Bastion. You can see this service like a managed jump box.
--I hope this helps and if it does, please don't forget to Accept it as an answer and "Up-Vote" the answer or message(s) that helped you so that it can help others in the community looking for help on similar topics
Regards,
Didier