- Home /
Question by
Master_Davicous · Oct 07, 2017 at 12:36 AM ·
rotationclamped rotation
Trouble rotating tank cannon.
Ok, so originally I had the rotation for the cannon working as intended, besides the fact that I could rotate it a full 360 degrees. Now, that I've successfully clamped the rotation between a certain angle, the other 2 axis of rotation do not seem to be going with it's parent, the tank's head.
Here is a gif of the problem I am having: https://gfycat.com/WeightyWellmadeGrayreefshark
Here is the code I currently have for the cannon rotation:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TankCannon : MonoBehaviour {
public float turnSpeed = 100;
public float maxRotation = 360.0f;
public float minRotation = 270.0f;
private float cannonRotation;
private float mouseY;
void Update ()
{
mouseY = -Input.GetAxis("Mouse Y");
cannonRotation = Mathf.Clamp(cannonRotation + mouseY * turnSpeed * Time.deltaTime, minRotation, maxRotation);
transform.rotation = Quaternion.Euler(cannonRotation, 0, 0);
}
}
Comment
Your answer
Follow this Question
Related Questions
How to use mathf.clamp? 2 Answers
How to Clamp a Quaternion Camera Rotation? 0 Answers
Clamp rotation of object - Door 1 Answer
Clamped rotation of turret problem 0 Answers
How to clamp rotation between negative and positive value 2 Answers