Hey guys,
I am having a little issue with a script I am writing for tank movement.
I am having a problem while rotating my tank base where it seems to go weird and lift off the ground suddenly.
Here is a video of the issue
This is my movement code which handles rotating and moving of the drifting tankvoid moveTank()
{
float mouseX = Input.GetAxis ("Mouse X");
float mouseY = Input.GetAxis ("Mouse Y");
float moveFB = Input.GetAxis ("Vertical");
float moveLR = Input.GetAxis ("Horizontal");
//Rotates the base of the tank
if(moveLR != 0)
{
//Rotator is an empty game object set at the location i wish to rotate around because for some reason i cannot find a way to change pivot in unity5 (In 4.6 I used to be able to parent the object to an empty gameobject and make it an offet)
//No idea why this line of code seems to be causing my tank to do what is shown in the video
m_GO_Tank.transform.RotateAround(m_GO_Rotator.transform.position, Vector3.up, (moveLR * m_F_TankRotationSpeed) * Time.deltaTime);
}
//Moves the tank forward and back
if (moveFB != 0)
{
m_Rb_TankRigidBody.AddForce (-1 * ((moveFB * m_GO_Tank.transform.right) * m_F_TankMoveSpeed),ForceMode.Acceleration);
}
//Rotates the turret
if(mouseX != 0)
{
m_GO_TankTop.transform.RotateAround(m_GO_Rotator.transform.position, m_GO_Rotator.transform.forward, (mouseX * m_F_TurretRotationSpeed) * Time.deltaTime);
}
//Moves the turret up and down within specified limits.
if (mouseY != 0)
{
Vector3 currentRot = m_GO_TankTurret.transform.localEulerAngles;
if(currentRot.x < m_F_MaxTurretAngle && currentRot.x > m_F_MinTurretAngle + 10)
{
m_GO_TankTurret.transform.localEulerAngles = new Vector3(m_F_MaxTurretAngle,0,0);
}
else if(currentRot.x > m_F_MinTurretAngle && currentRot.x < m_F_MaxTurretAngle - 10)
{
m_GO_TankTurret.transform.localEulerAngles = new Vector3(m_F_MinTurretAngle,0,0);
}
m_GO_TankTurret.transform.Rotate((mouseY * m_F_TurretVerticalSpeed) * Time.deltaTime,0,0,Space.Self);
m_GO_TankTurretMachineGun.transform.localEulerAngles = m_GO_TankTurret.transform.localEulerAngles;
}
}
The issue is mentioned in the code which shows the effected line.
Here is an image of the rotator used in the RotateAround in the inspector.
http://postimg.org/image/3xvbbckff/full/
I have not tested this on any other version of unity but I have tried alot of things like making sure there was no strange collider messing with the rotation or anything like that.
If anyone could help solve this strange issue, it would be great.
Thanks,
Kriogenic.