前提・実現したいこと
オブジェクトの周りを、一定の距離で回転する処理を実装したい。
かつ、生成位置に中心位置を固定し、生成オブジェクトが追尾しないようにしたい。
該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class subPlayer : MonoBehaviour { public float angle; //一秒あたりの回転角度 public Vector3 targetPos; //中心を求める変数 void Update () { Move(); } void Move() { /* Sampleを中心に自分を現在の上方向に、毎秒angle分だけ回転する。*/ /*回転軸をZに指定*/ Vector3 axis = transform.TransformDirection(Vector3.forward); /*実行処理*/ transform.RotateAround(targetPos, axis, angle * Time.deltaTime); } }
試したこと
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/25 11:45