facebook twitter hatena line email

「Unity/3d/2点間角度」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
行5: 行5:
  
 
参考:https://www.create-forever.games/distance-rotation-quaternion/
 
参考:https://www.create-forever.games/distance-rotation-quaternion/
 +
 +
==角度を上書き==
 +
xとzを0に
 +
<pre>
 +
var quaternion = Quaternion.LookRotation(target.position - player.position);
 +
target.transform.localRotation = quaternion;
 +
target.transform.localRotation = new Quaternion(0f, target.transform.localRotation.y, 0f, target.transform.localRotation.w);
 +
</pre>

2022年9月12日 (月) 16:55時点における版

var quaternion = Quaternion.LookRotation(target.position - player.position);
target.transform.localRotation = quaternion;

参考:https://www.create-forever.games/distance-rotation-quaternion/

角度を上書き

xとzを0に

var quaternion = Quaternion.LookRotation(target.position - player.position);
target.transform.localRotation = quaternion;
target.transform.localRotation = new Quaternion(0f, target.transform.localRotation.y, 0f, target.transform.localRotation.w);