Hello,
I’m using the scripts of FPS tutorial, and my problem is that I’ve inserted the crosshair, the the bullets don’t hit the center, instead they hit a little bit to the left.
How can I correct this?
Thank you.
Hello,
I’m using the scripts of FPS tutorial, and my problem is that I’ve inserted the crosshair, the the bullets don’t hit the center, instead they hit a little bit to the left.
How can I correct this?
Thank you.
The only way to always hit the crosshair point is to shoot from the camera instead of shooting from the weapon. This can be done perfectly with the machine gun (but not with the rocket launcher!) - just change the raycast origin in the first lines of the function FireOneShot (in MachineGun.js script):
...
function FireOneShot () {
var camTransf = Camera.main.transform; // get the camera transform
var hit : RaycastHit;
// use the camera transform in the raycast:
if (Physics.Raycast(camTransf.position, camTransf.forward, hit, range)) {
...
Now I get an error var camTransf = Camera.main.transform; // get the camera transform var hit : RaycastHit; // use the camera transform in the raycast: if (Physics.Raycast(camTransf.position, camTransf.forward, hit, range)) { // Apply a force to the rigidbody we hit if (hit.rigidbody) hit.rigidbody.AddForceAtPosition(force * direction <------- Here , hit.point); It says that direction is an unknown identifier.
– Sandr0GOk, I eliminated the direction variable - let's recreate it right after camTransf declaration: <pre> function FireOneShot () { var camTransf = Camera.main.transform; // get the camera transform var direction = camTransf.forward; // <- declare direction here var hit : RaycastHit; // use the camera transform in the raycast: if (Physics.Raycast(camTransf.position, direction, hit, range)) { ... </pre>
– aldonaletto
Might be a silly question, but is your crosshair centered? I'm wondering if it is positioned so that the left side is in the middle and the rest is off to the side...
– torrenteYou also might want to post the relevant parts of those scripts to get answers. Don't assume that people are familiar with any of the tutorials, or that they'll go and look them up.
– DrakestarI created a "plane" and dropped a crosshair texture with a transparent background onto the object. I made the plane a child of the camera. That way I could easily adjust the plane to align the bullet fire.
– DFiableThe crossair is centered, I could fix this just by putting the crosshaur a little bit to the left, but then the crosshair wouldn't be centered.
– Sandr0G