Help us understand the problem. What is going on with this article?

傾いた戦車でターゲットを狙う

More than 1 year has passed since last update.

```    // ターゲットを戦車座標系に
Vector3 dir = targetTr.position - cannonTr.position;
Quaternion invRot = Quaternion.Inverse(transform.rotation);
Vector3 invDir = invRot * dir;
```

TankCannonCtrl.cs
```using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TankCannonCtrl : MonoBehaviour {
[SerializeField] Transform targetTr; // 目標
[SerializeField] Transform turretTr; // 砲台
[SerializeField] Transform cannonTr; // 砲塔

// Use this for initialization
void Start () {
}

// Update is called once per frame
void Update () {
// ターゲットを戦車座標系に
Vector3 dir = targetTr.position - cannonTr.position;
Quaternion invRot = Quaternion.Inverse(transform.rotation);
Vector3 invDir = invRot * dir;
Quaternion turretRot = Quaternion.AngleAxis(turretAng, Vector3.up);
Quaternion cannonRot = Quaternion.AngleAxis(cannonAng, -Vector3.right);
turretTr.localRotation = turretRot; //Quaternion.Lerp(turretTr.localRotation, turretRot, 0.2f);
cannonTr.localRotation = cannonRot; //Quaternion.Lerp(cannonTr.localRotation, cannonRot, 0.2f);
Debug.DrawRay(cannonTr.position, cannonTr.forward * 100f);
}

{
return Mathf.Atan2(_dir.x, _dir.z);
}
{
float lxz = Mathf.Sqrt(_dir.x * _dir.x + _dir.z * _dir.z);
return Mathf.Atan2(_dir.y, lxz);
}
}
```

Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away