Hi guys. Im trying to make a linetrace from the muzzle of the weapon to the center of the screen, but i cant get it to work. I mean, yeah it kinda goes to the center of the screen if i shot from far far away, the problem is the offset is totally wrong when shooting near objects. I also tried to using the camera location instead of the socket location to set the end point, with the same result. Any ideas what could be wrong? heres two screenshots. Thanks in advance.
it depends where you are going to shoot to. I would imagine it is a ground there the center of the screen is. For that you need:
make a line trace from the camera location to camera location + direction * 5000 to get intersection with the surface (Hit results → location)
Now you are good to do a line trace from you muzzle to that intersection point from 1).
Yes. i ended doing it that way. But i wonder if there isnt a simpler method to do it. And why isnt working as it should with the setup i had.
This is the correct method of doing it as you need to specify an exact point where to shoot to. What you did is you traced from muzzle to muzzle + 5000*direction of the camera. But since your muzzle is not at the center of the screen you get that offset that you see on your first screenshot.
if your problem is solved, can you please mark it as answered?
I dont understand. The end point is muzzle location + forward vector of the camera. It should be pointing to the center of the screen. Anyways, not going to keep my mind busy more time with it lol. Btw, i dont have a clue how to make the post answered.
“It should be pointing to the center of the screen”
it is hard for you too see because you are too close to the center (but not quite there). Place you muzzle to extreme, like a side of your screen. Then add a forward vector of your camera to the muzzle. It will never point to the center of the screen.