- Home /
Tank stabilization
Hi! I using standart mouselook script for my tank turret and gun and its works fine, but now I need vertical and horizontal stabilization. This means that the turret should not repeat the tank Y axis rotation, and rotate that axis only by mouselook script. Gun also should not repeat the rotation of the tank, but only on the X axis and also rotate that axis by mouselook script, plus the have a limit of rotation, taking into account the the tank rotation. Is that possible?
Here some pictures of tank stabilization
Answer by haim96 · Dec 08, 2013 at 11:57 AM
assuming that you need to stabilize the gun on target. you could set point in space by mouse and make the gun lookat that point. you can also check the rotation and limit it if it too high. i hope it's help somehow.
Yeah I think about it and maybe this is best solution. Now I need to understand how is should work.
search google for "unity lookat one axis" you may find several script examples for this. now make the turret rotate in one axis (left or right) and the barrel in the other axis (up or down).
Okey now I have vertical stabilization script without lookat, just with free mouse look, but I have problem. #pragma strict
var tank : Transform;
var $$anonymous$$Angle : float;
var maxAngle : float;
private var rotX : float = 0;
private var angle :float = 0;
function Update () {
var tankX = tank.transform.eulerAngles.x;
angle -= Input.GetAxis("$$anonymous$$ouse Y") * 0.5;
angle = $$anonymous$$athf.Clamp(angle,$$anonymous$$Angle,maxAngle);
rotX = angle-tankX;//20*$$anonymous$$athf.Sin(Time.time);
rotX = $$anonymous$$athf.Clamp(rotX,$$anonymous$$Angle,maxAngle);
transform.localEulerAngles = Vector3(rotX,0,0);
print(tankX);
}
tank.transform.eulerAngles.x
gives me strange angle. I tried $$anonymous$$athf.Rad2Deg(tank.transform.rotation.x)*2
also not works fine. How to get normal tank X axis angle?
Your answer
Follow this Question
Related Questions
Rotation around Z axis wont lock correctly (2D) 1 Answer
Rotation too complicated 3 Answers
How to make the camera to focus on a player 1 Answer
how can a camera zoom into a game object? 3 Answers
Lerp Rotation broken 1 Answer