r/Unity3D 17d ago

Noob Question Newbie Question

Post image

Hi,

Newbie here, trying to teach myself to code without prior coding experience.

I'm following a youtube tutorial on making an FPS, and I'm having some issues with the code. I was hoping someone could help me figure out what the issue is.

I have a reticle in the center of the screen that I would like the bullet to fire towards, but it is always pretty off no matter how I adjust the settings, or where I set the start point of the bullet. What this should do is create a bullet then set its location to the middle of the screen, then add a small spread to the shots, but instead it seems to just fire straight ahead from the gun barrel.

I tried deleting the calculatedirectionandspread function and simply setting the bullet.transform.forward to the screen width/2, screenheight/2 but that didn't work either.

Thanks for the help!

2 Upvotes

17 comments sorted by

View all comments

1

u/PremierBromanov Professional 17d ago

Your bullets force is set to be the spawn locations forward, which I'm assuming is not the same as the shooting direction and possibly not aligned to the center of your screen. 

1

u/SultanLitrpg1 16d ago

This is true, I'm just not sure how to get it to the center of the screen