Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Can clamp X axis but NOT Y axis on my rotation

$
0
0
Hello, I have been trying for days, I read every single post I could find on Reddit, StackOverflow, Unity forums, nothing helped. I am seriously desperate now. Answer there is pretty much always the same, I studied every single answer but none of those helped solve my problem. And god knows I spent time on this ! Now, my X axis is clamped properly. That is beautiful, my gun only goes from +10 deg. up and -10 deg. down. For the Y axis, impossible. Just impossible. What I am currently doing is trying to clamp my barrel's Y between -35 and +35 degrees, I got it working when the gun's (parent) Y = 0, but if I start moving my gun around and rotate it the other way around so 180 degrees, then my barrel just doesn't want to move left anymore. Pictures describing the issue : ![alt text][1] ![alt text][2] [1]: /storage/temp/189666-help1.jpg [2]: /storage/temp/189667-help2.jpg Here is the code I use for the rotation : //Adjusting the turret tmpRotation = turret.localRotation; targetPointTurret = (pointingAt - turret.position).normalized; // Getting the pointing direction targetRotationTurret = Quaternion.LookRotation(targetPointTurret, turret.parent.transform.up); // Keeping the rotation flat based on the hull's rotation // Always firing straight if (traverse == 0) targetRotationTurret = Quaternion.Euler(targetRotationTurret.eulerAngles.x, targetRotationTurret.eulerAngles.y, targetRotationTurret.eulerAngles.z); // Updating the final rotation else { // Getting the axis to clamp clampedY = targetRotationTurret.eulerAngles.y; Debug.Log(clampedY); if (clampedY > 180) clampedY -= 360; clampedY = Mathf.Clamp(clampedY, GameGO.instance.activePlayerGO.transform.rotation.eulerAngles.y - traverse, GameGO.instance.activePlayerGO.transform.rotation.eulerAngles.y + traverse); // Actually clamping targetRotationTurret = Quaternion.Euler(targetRotationTurret.eulerAngles.x, clampedY, targetRotationTurret.eulerAngles.z); // Updating the final rotation } turret.rotation = Quaternion.RotateTowards(turret.rotation, targetRotationTurret, Time.deltaTime * GameGO.instance.activePlayerGO.unit.TurretRotatingSpeed); turret.localRotation = Quaternion.Euler(tmpRotation.eulerAngles.x, turret.localRotation.eulerAngles.y, tmpRotation.eulerAngles.z);

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>