Shooting exactly to the center of screen
Hi everyone, I know this question has been asked quite a few times, but mine is a bit strange
As you see in the screenshot, the bullet i shoot does not go exactly to the center of the screen where the crosshair is, there is a little gap between them.
Here is my script :
private void StartBullet()
{
GameObject bullet = Instantiate(BulletPrefab, BulletSpawner.transform.position, BulletSpawner.transform.rotation);
float x = Screen.width / 2;
float y = Screen.height / 2;
var ray = Camera.main.ScreenPointToRay(new Vector3(x, y, 0));
bullet.GetComponent<Rigidbody>().velocity = ray.direction * 8;
Destroy(bullet, 3f);
}
What am-i doing wrong ? Thanks in advance !
shoot.png
(222.2 kB)
Comment
Your answer
Follow this Question
Related Questions
How to get bullet hole to wrap around corners of objects? 0 Answers
In 3d multiplayer fps how can I make the crosshair such that other users can not see my crosshair? 1 Answer
Shooting Gun Script 4 Answers
Third person controller moving backwards when shooting 0 Answers
Finding target position for particle system based shooting 0 Answers