- Home /
FPS Tutorial problem
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.
$$anonymous$$ight 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...
You 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.
I 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.
The 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.
Answer by aldonaletto · Jun 28, 2012 at 06:26 AM
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.
Ok, I eli$$anonymous$$ated the direction variable - let's recreate it right after camTransf declaration:
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)) { ...
Your answer
Follow this Question
Related Questions
FPS Bullets Generic Solution. How? 2 Answers
colliding bullets 2 Answers
Problems with Dani's Karlson FPS Movement Controller 1 Answer
spraying bullets 3 Answers