敵を動かす③(途中で方向転換)



途中で方向転換
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeDirection : MonoBehaviour
{
private Rigidbody rb;
private Vector3 pos;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
pos = transform.position;
if(pos.z < 0)
{
// いったん速度を0にする。
rb.velocity = Vector3.zero;
// 異方向に力を加える。
rb.AddForce(new Vector3(300, 0, 300) * Time.deltaTime * -30);
}
}
}





【2019版】Danmaku Ⅱ(基礎2/全38回)
他のコースを見る


途中で方向転換
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeDirection : MonoBehaviour
{
private Rigidbody rb;
private Vector3 pos;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
pos = transform.position;
if(pos.z < 0)
{
// いったん速度を0にする。
rb.velocity = Vector3.zero;
// 異方向に力を加える。
rb.AddForce(new Vector3(300, 0, 300) * Time.deltaTime * -30);
}
}
}





敵を動かす③(途中で方向転換)