Hello, What i want is pretty easy, I have a tank, so a turret and a hull. Both rotate perfectly fine. But the turret’s rotation speed is not calculated depending on the hull’s rotation speed.
Another way of saying it is : both hull and turret rotates at 25 degres/sec no matter what happens. I’d like to make it so when the hull is rotating left and the turret right, the turret stays still (the hull’s rotation cancels out the turret’s rotation since it’s rotating the opposite way). And if the turret is rotating left and the same for the hull, then the turret goes twice faster (hull rotation speed + turret rotation speed)
And here’s the code to make the whole tank rotates
Note that the Camera is a child of the hull. Turret and Hull are both direct Children of the tank gameobject.
Thanks for any help [2]: /storage/temp/155069-2.jpg
Ok, I’ve built many a tank game, and from what you said about the tank it works like this:
Tank Gameobejct (empty) has tank script (rotates)
Hull Gameobject (model) doesn’t have any scripting (maybe shaders, do they count?)
Turret Gameobject (model)
Camera
This if this is how the tank is laid out, then the script on the tank parent should just need a reference to the turret model and rotate that. If the tank parent is rotating, then the children would rotate as well, meaning that no additional calculations are required.
However, if for some reason you don’t want to have your tank laid out that way, or cannot for some reason when you rotate the hull of the tank you could also get a reference to the turret and rotate it as well. (In addition to moving the turret on the controller) This way, if you are moving both tank and turret it would move approperetly. (spelling. and this would act the same as putting the tank in the layout I suggested.
IF you want the tank to keep aiming at the same place, and use the tank turret control only to move the turret, then you could set it up so when you move the tank hull, check if the control to move the turret is active, and if it is, then move it along with the hull. (In addition to moving the turret on the controller) Otherwise, it will keep aiming at the same location.