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

Clamping turret rotation on Y axis not working

$
0
0
Hello everyone ! Here is my issue, I have a gun, I am trying (I technically succeeded) to clamp its rotation on the Y axis between -35 and 35 degrees, and I mean it works, but for some reason this -35 / 35 degrees angle is behind the gun ?? I want it to be in front of it, not behind, like 0 degrees should be in front of the object, I don't understand haha Here is my code : ray = cam.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); // Shooting where the crosshair is at, middle of the screen pointingAt = ray.origin + ray.direction * 100; if (turret) { //Adjusting the turret tmpRotation = turret.localRotation; targetPointTurret = (pointingAt - turret.position).normalized; targetRotationTurret = Quaternion.LookRotation(targetPointTurret, turret.parent.transform.up); if (gunTraverse == 0) targetRotationTurret = Quaternion.Euler(targetRotationTurret.eulerAngles.x, targetRotationTurret.eulerAngles.y, targetRotationTurret.eulerAngles.z); // Updating the final rotation else { // Clamping the left right axis of the gun clampedY = targetRotationTurret.eulerAngles.y; // Getting the axis I want to clamp if (clampedY > 180) clampedY -= 360; // We need that clampedY = Mathf.Clamp(clampedY, -(gunTraverse / 2), gunTraverse / 2); 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); } here's a pic of how it looks : ![alt text][1] [1]: /storage/temp/189190-capture-decran-2021-11-26-a-0842-copie.jpg

Viewing all articles
Browse latest Browse all 592

Trending Articles