Almost positive I know your issue. I think you need to use cannon.transform.rotation (not local rotation) and cannon.InverseTransformDirection instead of Transform Direction for these two lines: [changes bolded]
--->clone = Instantiate(Bullet, cannon.transform.position, **cannon.transform.rotation**);
--->clone.velocity = **cannon.InverseTransformDirection** (Vector3.forward * bulletSpeed);
I say rotation instead of localRotation for the same reason you used position instead of localPosition [Almost positive I've seen it that way (e.g. position, rotation) everytime].
For InverseTransformDirection, I say this because we want to move from local to worldspace, since rigidbodies work in worldspace.
Read up on the differences between:
[rotation][1]:
the rotation of the object with respect to the world.&&
[localRotation][2]:
the rotation of the object with respect to its parent (for cameras, the local rotation is usually forward (with respect to the parent or the player/controller/character), but the (world) rotation of a camera is anything but forward, since the player is constantly moving and turning.
__________________
[TransformDirection][3]:
In the case of a camera, give the computer a direction in the world and transfer into into a direction as the player would see it.&&
[InverseTransformDirection][4]:
Also in the case of a camera, give the computer a direction as the player sees it, then change it to how the components (in your case, the rigidbody) would feel it in the real world.
Sorry, if any of this is wrong, but this code will at least point you in the right direction (pun intended).
[1]: http://unity3d.com/support/documentation/ScriptReference/Transform-rotation.html
[2]: http://unity3d.com/support/documentation/ScriptReference/Transform-localRotation.html
[3]: http://unity3d.com/support/documentation/ScriptReference/Transform.TransformDirection.html
[4]: http://unity3d.com/support/documentation/ScriptReference/Transform.InverseTransformDirection.html+
↧