Rotation, Cannon, Tank, Problem

I have a tank.

On my tank is a turret.

Attached to the turret is a cannon.

If I attach both the turret and the cannon directly to the tank, they rotate fine.

I need to have my cannon follow the position of the turret, so I attach the cannon directly to the turret.

Where my Y rotation worked before, it ceases to function properly.

Anyone help?

226523–8166–$cannon_807.rar (2.09 KB)

Small bump.

There is nothing wrong with the prefab.
Can you show us the script to control it?

Of course, I’ve not seen the code, but just a guess… are you using transform.rotation to set the elevation of the gun? If so, you probably need to use transform.localRotation instead.

I tried that.

Here’s how I fixed it.

I made a cylinder in 3ds max with it’s origin at one end of the cylinder instead of using the unity3d primitive cylinder whose origin was the center of the primitive. Now, when it rotates, it pivots on one end, rather than the center.

That’s the simplest way to get round it.

Alternatively, I suppose you could also parent the cylinder of the barrel to another object (a cube, say, placed where you want the pivot to be), and rotate the parent?

However I’d say making your own meshes is generally a better method of doing things anyway.

No.

That’s the first thing I tried. It doesn’t behave itself very well.

I did that with making a cannon turret and it worked fine. A sphere with multiple cylinders that recoiled when they fired and moved when the sphere was rotated.
All using Unity primitives.

Want the script and prefab?

That’d be awesome!

I keep trying to add the file as an attachment here but I get a “no post mode error” every time.
I’ll host the file somewhere and then link to it.
Should be another day or so.