Make bullet fly exactly in the center of screen
Hi everyone. could someone explain me how can i shoot exactly in the center of the screen from any position? I have here my character in third person. The camera rotates with a free looking cinemachine camera. The red sphere is the fire origin. The grey sphere is the current bullet. And the white dot is where i want the bullet to go. No Matter in which direction i rotate. Could someone help?
https://i.imgur.com/lVwQIb0.png
void Shoot(){
Ray mouseRay = GetComponent<PlayerBase>().cam.ScreenPointToRay(Input.mousePosition);
float mouseDir = ( GetComponent<PlayerBase>().transform.forward - GetComponent<PlayerBase>().cam.transform.position).magnitude * 1f;
GetComponent<PlayerBase>().shootOrigin.transform.LookAt(mouseRay.origin + mouseRay.direction * mouseDir);
Instantiate(attack[0], GetComponent<PlayerBase>().shootOrigin.position, GetComponent<PlayerBase>().shootOrigin.rotation);
}
Your answer
Follow this Question
Related Questions
How to choose a specific game object with a tag from multiple game objects with that tag? 0 Answers
Make an object follow and face an object while maintaining distance from a different object. 0 Answers
,how to set max rotation for camera in third person game 0 Answers
Make camera follow and look at object at the same time 0 Answers
Help with setting up 2D auto scrolling camera using Cinemachine 1 Answer