Raycast crosshair

Hello to everyone. I want the bullet fired from my gun to coincide with the crosshair. I point the gun as the starting point with Raycast. The end point is the plus sign. But it does not exactly correspond to the plus sign. Does anyone have any suggestions?

Assuming your gun is off center and the bullet is an actual entity and not a raycast:

Generally games that have this will cast a raycast from the camera through the crosshair and whatever it hits, will fire the projectile from the spawn point (the end of the gun) to where the raycast intersected with the world.

For additional effect, the gun can be rotated to look at what the raycast hit.

1 Like
 var start=this.sights.getPosition(); // my crosshair
  var to = start.clone();
  var bullet = this.app.systems.rigidbody.raycastFirst(start, to);

where am i making a mistake?

Is sights definitely your cross hair rather than anything on your gun?

Is forward of the sights the same direction as the camera?

1 Like

I changed the position of the cross hair according to the weapon. Thanks

Err. Doesn’t that mean that the cross hair moves? Shouldn’t it be at the center of the screen?

no hair cross fixed. I just adjusted the local position.