void Update()
{
timer += Time.deltaTime;
if (isShoot && timer >= delayShoot)
{
// Shoot
GameObject newShell = (GameObject)Instantiate(shellPrefab, gun.position + gun.forward * 1.8f, Quaternion.identity);
Collider colliderTank = GetComponent<Collider>(); // Unity 5 Compatible
Physics.IgnoreCollision(colliderTank, newShell.GetComponent<Collider>());
Rigidbody rbShell = newShell.GetComponent<Rigidbody>(); // Unity 5 Compatible
rbShell.AddRelativeForce(gun.forward * powerShoot, ForceMode.Impulse);
isShoot = false;
timer = 0f;
}
// Move the character
Vector3 moveDirection = Vector3.zero;
if (chcr.isGrounded)
{
moveDirection = new Vector3(deltaMove.x, 0f, deltaMove.y);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
chcr.Move(moveDirection * Time.deltaTime);
// Rotate the character (world space)
if (Mathf.Abs(deltaRot.x) > 0.5f || Mathf.Abs(deltaRot.y) > 0.5f)
{
Vector3 relativePos = new Vector3(deltaRot.x, 0f, deltaRot.y);
Quaternion targetRot = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, Time.deltaTime * 2f);
}
deltaMove = Vector2.zero;
deltaRot = Vector2.zero;
}