How do i instantiate gameobject on touch and Shoot it like in the Smash hit game? I don’t want it to shoot forward using Addforce(Vector3.forward) Rather i want to shoot it to the mouseposition from camera.
First of all, you need to convert the touch position into the world. For this you use ScreenToWorldPoint on the Camera with the Input.position:
Even though the Vector given by the input is a Vector2, the transfer needs a Vector3. That’s because if the camera is in perspective mode, this would be at the origin of the camera only, where all positions would be returned as the position of the camera. you’d need to define z as the distance from the camera you want the ray to start from, preferably the near clip plane distance of the camera. If you then use the camera’s forward vector for your addForce after instantiating your object at the point you received from your conversion, it should fly off from where you tabbed and along the view direction.
If you instead use the point you generated minus the camera position as your AddForce, it will fly perspectively away.