(スクリプト)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour
{
private Rigidbody rb;
public float speed;
public GameObject cam;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveH, 0, moveV);
// カメラの向きとボールの進行方向を合致させる。
Vector3 desiredMove = cam.transform.forward * movement.z + cam.transform.right * movement.x;
rb.AddForce(desiredMove * speed);
}
}
(設定)