現在、Unityで3Dシューティングゲームを制作しています。そこで、敵をランダムに移動させようと思い、Vector3.Slerpで移動させようとしたのですが、瞬間移動のようになってしまいます。
滑らかに動かすことはできないのでしょうか。
敵のコードは以下です。
using System.Collections; using System.Collections.Generic; using UnityEngine; public class BossPitControl : MonoBehaviour { public GameObject PitLaser; public GameObject Explosion; float point_X; float point_Y; float point_Z; float Z_Speed = 30; float attackintervalTime; float maxLife = 50; float life; float speed = 120; void Start () { life = maxLife; } void Update () { transform.position += transform.forward * Time.deltaTime * -1 * Z_Speed; attackintervalTime += Time.deltaTime; if (attackintervalTime >= 1) { attackintervalTime = 0.0f; Attack(); } if (life <= 0) { Instantiate(Explosion, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity); Destroy(this.gameObject); BossControl.PitRest -= 1; } } void Attack() { GameObject player = GameObject.FindWithTag("Player"); point_X = Random.Range(-30.0f, 30.0f); point_Y = Random.Range(-10.0f, 10.0f); point_Z = transform.position.z; transform.position = Vector3.Slerp(transform.position, new Vector3(point_X, point_Y, point_Z), Time.deltaTime * speed); Quaternion quat = Quaternion.Euler(0, 180, 0); Instantiate(PitLaser, new Vector3(transform.position.x, transform.position.y, transform.position.z), quat); } void OnTriggerEnter(Collider coll) { if (coll.gameObject.tag == "PlayerBullet") { life -= 10; } if (coll.gameObject.tag == "PlayerMissile") { life -= 20; } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/17 06:43
2017/09/17 08:10
2017/09/17 09:21