• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kyoogi · Apr 03, 2017 at 06:50 AM · rotationturrettankfloatingcannon

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;
 }

}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dvandamme · Apr 03, 2017 at 11:32 AM 0
Share

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

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I rotate a tank's turret back to the starting turret position? 2 Answers

question about turret on tank 1 Answer

rotating a tank turret while the tank is rotating 3 Answers

Rotate on Z axis 2 Answers

Lock rotation of object 4 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges