敵を動かす⑤(8の字移動)
![Cc424230 4d1c 43c7 a830 67316623c3b8](https://codegenius.org/uploads/slide/image/4872/cc424230-4d1c-43c7-a830-67316623c3b8.jpeg)
![90424236 4ac9 4439 9b0d e8f90c393a31](https://codegenius.org/uploads/slide/image/4873/90424236-4ac9-4439-9b0d-e8f90c393a31.jpeg)
![3f5a4b1c 6131 447a 88aa b671e7c76f79](https://codegenius.org/uploads/slide/image/4874/3f5a4b1c-6131-447a-88aa-b671e7c76f79.jpeg)
8の字移動
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy8Move : MonoBehaviour
{
private float angle;
private Vector3 pos;
private void Start()
{
pos = transform.position;
}
void Update()
{
// 移動速度に相当
angle += Time.deltaTime * 1.2f;
transform.position = new Vector3(
// X軸の幅
pos.x + Mathf.Sin(angle) * 6,
// Y軸
pos.y + transform.position.y,
// Z軸の幅
pos.z + Mathf.Sin(angle * 2) * 2);
}
}
![384d5c8b d5a6 4bcf 9003 8f1c6f3bfa1e](https://codegenius.org/uploads/slide/image/4875/384d5c8b-d5a6-4bcf-9003-8f1c6f3bfa1e.jpeg)
![A68b89ac 52c4 4519 85b7 649eb64ae876](https://codegenius.org/uploads/slide/image/4876/a68b89ac-52c4-4519-85b7-649eb64ae876.jpeg)
![6f775595 94ae 42fd 94cc f12a7d74a280](https://codegenius.org/uploads/slide/image/4877/6f775595-94ae-42fd-94cc-f12a7d74a280.jpeg)
![214937f6 4bc1 451f 88a2 600f24dc3260](https://codegenius.org/uploads/slide/image/4878/214937f6-4bc1-451f-88a2-600f24dc3260.jpeg)
![850b2cc4 76ca 41c8 afce a51030e3b9b3](https://codegenius.org/uploads/slide/image/4879/850b2cc4-76ca-41c8-afce-a51030e3b9b3.jpeg)
![023e2702 ad3c 46d6 aa2a 0e4aaf3999b6](https://codegenius.org/uploads/slide/image/4880/023e2702-ad3c-46d6-aa2a-0e4aaf3999b6.jpeg)
8の字移動(改良)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy8Move : MonoBehaviour
{
private float angle;
private Vector3 pos;
// ★改良
private float plus;
private void Start()
{
pos = transform.position;
}
void Update()
{
angle += Time.deltaTime * 1.2f;
// ★改良
// Z軸方向への移動速度に相当
plus -= 0.05f;
transform.position = new Vector3(
pos.x + Mathf.Sin(angle) * 6,
pos.y + transform.position.y,
// ★改良
pos.z + plus + Mathf.Sin(angle * 2) * 2);
}
}
![F5a7beb8 f12f 42fa a396 d398ff6a85b9](https://codegenius.org/uploads/slide/image/4881/f5a7beb8-f12f-42fa-a396-d398ff6a85b9.jpeg)
【2019版】Danmaku Ⅱ(基礎2/全38回)
他のコースを見る![Cc424230 4d1c 43c7 a830 67316623c3b8](https://codegenius.org/uploads/slide/image/4872/cc424230-4d1c-43c7-a830-67316623c3b8.jpeg)
![90424236 4ac9 4439 9b0d e8f90c393a31](https://codegenius.org/uploads/slide/image/4873/90424236-4ac9-4439-9b0d-e8f90c393a31.jpeg)
![3f5a4b1c 6131 447a 88aa b671e7c76f79](https://codegenius.org/uploads/slide/image/4874/3f5a4b1c-6131-447a-88aa-b671e7c76f79.jpeg)
8の字移動
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy8Move : MonoBehaviour
{
private float angle;
private Vector3 pos;
private void Start()
{
pos = transform.position;
}
void Update()
{
// 移動速度に相当
angle += Time.deltaTime * 1.2f;
transform.position = new Vector3(
// X軸の幅
pos.x + Mathf.Sin(angle) * 6,
// Y軸
pos.y + transform.position.y,
// Z軸の幅
pos.z + Mathf.Sin(angle * 2) * 2);
}
}
![384d5c8b d5a6 4bcf 9003 8f1c6f3bfa1e](https://codegenius.org/uploads/slide/image/4875/384d5c8b-d5a6-4bcf-9003-8f1c6f3bfa1e.jpeg)
![A68b89ac 52c4 4519 85b7 649eb64ae876](https://codegenius.org/uploads/slide/image/4876/a68b89ac-52c4-4519-85b7-649eb64ae876.jpeg)
![6f775595 94ae 42fd 94cc f12a7d74a280](https://codegenius.org/uploads/slide/image/4877/6f775595-94ae-42fd-94cc-f12a7d74a280.jpeg)
![214937f6 4bc1 451f 88a2 600f24dc3260](https://codegenius.org/uploads/slide/image/4878/214937f6-4bc1-451f-88a2-600f24dc3260.jpeg)
![850b2cc4 76ca 41c8 afce a51030e3b9b3](https://codegenius.org/uploads/slide/image/4879/850b2cc4-76ca-41c8-afce-a51030e3b9b3.jpeg)
![023e2702 ad3c 46d6 aa2a 0e4aaf3999b6](https://codegenius.org/uploads/slide/image/4880/023e2702-ad3c-46d6-aa2a-0e4aaf3999b6.jpeg)
8の字移動(改良)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy8Move : MonoBehaviour
{
private float angle;
private Vector3 pos;
// ★改良
private float plus;
private void Start()
{
pos = transform.position;
}
void Update()
{
angle += Time.deltaTime * 1.2f;
// ★改良
// Z軸方向への移動速度に相当
plus -= 0.05f;
transform.position = new Vector3(
pos.x + Mathf.Sin(angle) * 6,
pos.y + transform.position.y,
// ★改良
pos.z + plus + Mathf.Sin(angle * 2) * 2);
}
}
![F5a7beb8 f12f 42fa a396 d398ff6a85b9](https://codegenius.org/uploads/slide/image/4881/f5a7beb8-f12f-42fa-a396-d398ff6a85b9.jpeg)
敵を動かす⑤(8の字移動)