|
I'm working on a FPS game, and have only a little knowledge about scripting and animations. I encountered a problem, spent all day long searching answers for it, still no hope. I attached this script :
into my camera, but when i press shoot, it shoots the bullet all around. Even if im aming at the same spot, sometimes it shoots upward, sometimes it shoots downwards, sometimes from the centre, sometimes from below, even from on top. How do i fix this problem? Also, can anyone give me a scrip suitable for a gun that shoots using raycast? REALLY needed help, thanks.
(comments are locked)
|
|
From the Unity Rigidbody.velocity documentation:
Instead of setting the object velocity, add force to the object:
I've not tried instantiating a Rigidbody before, only a Transform/GameObject prefab, but I can't think of a reason it wouldn't work. Try pasting this code over yours. its still the same.... my real problem is that the projectile is being shot randomly... when im standing on a plane, sometimes the bullet even goes beneath the plane....
Jun 16 '10 at 11:11 AM
user-3061 (yahoo)
I suspected that adding a velocity directly to the Rigidbody was the cause of the random direction. Does your script look exactly like the code I've got in my answer? (updated to include the whole script)
Jun 16 '10 at 11:39 AM
Marowi
its exactly the same..
Jun 16 '10 at 11:43 AM
user-3061 (yahoo)
By the way, i put the script inside the camera, which is a child of my controller
Jun 16 '10 at 11:45 AM
user-3061 (yahoo)
I've tested this locally, adding the script to the camera, and it works fine. I've changed the Rigidbody variables to Transform. Can you try the script in the updated answer and let me know how it goes? Are there any scripts on the projectile prefab?
Jun 16 '10 at 12:06 PM
Marowi
(comments are locked)
|
|
Is it possible that you have a collider on your camera that is colliding with your projectile? Use
Edit: moved from comment to answer how do i put it inside the script?
Jun 16 '10 at 12:49 PM
user-3061 (yahoo)
You add this to the part of your code where you instantiate the bullet, any time after it has been created. The first value is the collider on the new object, "clone.collider"; and the second is the collider on the thing that fired it, "collider" (that is the one attached to the same object as the script).
Jun 16 '10 at 12:51 PM
Novodantis 1
Nope, its not the collision who caused this, because ive tried using an empty object attached with the script, and the result is the bullet falling below the ground..... this is really frustrating.....
Jun 16 '10 at 12:56 PM
user-3061 (yahoo)
If nothing is working still, try making the projectile from scratch: a sphere with the collider removed and a rigidbody added (gravity disabled).
Jun 16 '10 at 01:10 PM
Novodantis 1
thanks, finally got it working, but still, i have to set the speed to 10000 to get it working like rocket speed...
Jun 16 '10 at 01:21 PM
user-3061 (yahoo)
(comments are locked)
|
|
I changed this Into And it worked :o
(comments are locked)
|
I hope that it works ;)
(comments are locked)
|
|
Your Bullet will always fire at what it is attached to, so if you attach the bullet with the firing script, and a small invisible square without a mesh, then it should fire at, and through, the square
(comments are locked)
|
