Skip to content

Instantly share code, notes, and snippets.

@todorok1
Last active April 9, 2018 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/0ddc46435deac8bf3e0dfa3564523637 to your computer and use it in GitHub Desktop.
Save todorok1/0ddc46435deac8bf3e0dfa3564523637 to your computer and use it in GitHub Desktop.
Unityチュートリアル・斜方投射のスクリプト。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SphereBooster : MonoBehaviour {
// Use this for initialization
void Start () {
// 力を加える向きをVector3型で定義
// 今回はX軸から45度の向きに射出するため、XとYを1:1にする
Vector3 forceDirection = new Vector3(1.0f, 1.0f, 0f);
// 上の向きに加わる力の大きさを定義
float forceMagnitude = 10.0f;
// 向きと大きさからSphereに加わる力を計算する
Vector3 force = forceMagnitude * forceDirection;
// SphereオブジェクトのRigidbodyコンポーネントへの参照を取得
Rigidbody rb = gameObject.GetComponent<Rigidbody>();
// 力を加えるメソッド
// ForceMode.Impulseは撃力
rb.AddForce(force, ForceMode.Impulse);
}
// Update is called once per frame
void Update () {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment