- Home /
Rotating turret floats off tank in a sideways circle. Cannon floats out of turret when rotating up.
Hello, I'm very new to programming and unity so please bear with me. So, my turret rotates around and way from the body of my tank instead of just spinning on top of my tank. My cannon rotates up but begins to float above the turret like it's rotating around an invisible circle.
my code:
using UnityEngine; using System.Collections;
public class TurretControls : MonoBehaviour {
public Transform turretPivot;
public Transform cannonPivot;
public float turretSpeed = 45f;
public float cannonSpeed = 20f;
public float lowCannonLimit = 315f;
public float highCannonLimit = 359.9f;
public void RotateTurret(float direction) {
Vector3 rotate = Vector3.up * turretSpeed * direction * Time.deltaTime;
turretPivot.Rotate (rotate);
}
public void RotateCannon(float direction) {
float rotate = cannonSpeed * direction * Time.deltaTime;
Vector3 euler = cannonPivot.localEulerAngles;
euler.x = Mathf.Clamp (euler.x - rotate, lowCannonLimit, highCannonLimit);
cannonPivot.localEulerAngles = euler;
}
}
that time when someone responds to your question with a link to a tutorial.,,,, yeah, thats this time... but seriously... run through the entire (which ive just linked to the tank control specific section) https://unity3d.com/learn/tutorials/projects/tanks-tutorial/tank-creation-control?playlist=20081
Your answer
Follow this Question
Related Questions
Rotate on Z axis 2 Answers
Lock rotation of object 4 Answers
tank-tower rotation works unexpected 2 Answers
How can I rotate a tank's turret back to the starting turret position? 2 Answers
question about turret on tank 1 Answer