//
// Screen space (viewport) coordinates are between 0..1 so 0.5 on both the x and y is
// the screen centre.
//
Vector3 screenSpaceCenter = new Vector3(0.5f, 0.5f, 0);
//
// Convert that to a world point where myCamera needs to be changed to be
// your actual camera.
//
Vector3 laserEnd = myCamera.ViewportToWorldPoint(screenSpaceCenter);
//
// Shoot towards laserEnd
//
That solution will be adequate if the projectiles always go to the center of the screen and the spaceship doesn’t move. If it does move and the lasers go to a point in front of it rather than a static position at the center of the screen that solution will not work.
Yeah… It’s not working. Like outwarddesign said, spaceship is moving and it’s not working.
@
Solved.
public Camera myCamera;
float x = Screen.width / 2;
float y = Screen.height / 2;
var ray = myCamera.ScreenPointToRay(new Vector3(x, y, 0));
clone.velocity = ray.direction * 80;