2019年6月23日日曜日

unity 当たったところからパーティクル

unity 当たったところからパーティクル

マウスカーソルの位置へRayを飛ばして、当たった部分の位置と法線ベクトルを取得。
パーティクルのオブジェクトをその位置と方向に設定する。

シーン設定

  • 当たり対象物のキューブを回転して拡大して配置。
  • どちらを向いているかわかりやすいパーティクルを1つ置く。
  • mainCtrlスクリプトを取り付けた空ゲームオブジェクトが1つ。
  • mainCtrlのオブジェクトはインスペクタでパーティクルオブジェクトを渡しておく。

mainCtrl.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mainCtrl : MonoBehaviour {
	void Start () {
	}
	[SerializeField] Transform particleObj;
	RaycastHit hit;
	// Update is called once per frame
	void Update () {
		Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
		bool is_hit = Physics.Raycast (ray, out hit, 1000);
		if (is_hit) {
			particleObj.transform.position = hit.point;
			particleObj.rotation = 
				Quaternion.FromToRotation (transform.forward, hit.normal);
		}
	}
}

2019年6月19日水曜日

Mixamoのアニメーションをunityで再生

Mixamoのアニメーションをunityで再生まで

とりあえずの手順おぼえがき。

1

まずこんなモデルがあり、Mixamoに取り込んでいる状態とします。
enter image description here

2

このモデルにアニメーションを付ける前にT-Poseのままfbxのデータとしてダウンロードします。
enter image description here

3

アニメーションをつけます。
enter image description here

4

without skinでアニメーションのみをダウンロードします。
enter image description here

5

2つのfbxファイルをunityに取り込みます。
enter image description here

6

t-poseの方で取り込み基本設定
enter image description here

7

Rigの設定Humanoidにする
enter image description here

8

Animationの設定T-poseのみなのでここは取り込むものはない
enter image description here

9

アニメーションのみのfbxの基本設定
enter image description here

10

RigはT-poseの方のAvatarを使います。
enter image description here

11

Animationの設定をお好みで。とりあえずLoopしておきましょう。
enter image description here
モデルの取り込みが完了しました。

12

アニメーションさせるためにSceneに配置します。
enter image description here

13

AnimationControllerをつくり
enter image description here

14

配置したモデルのAnimatorに取り付けます。
enter image description here

15

AnimatorControllerをダブルクリックしてひらき、編集します。
Animationデータからクリップをとりあえずデフォルトに配置
enter image description here

16

実行するとアニメーションが再生されます。
enter image description here

追記:Timeline使ったら簡単だった

17

新しいシーンにモデルを配置します
enter image description here

18

unityのタイムラインのウィンドウを開きます。
enter image description here

19

配置したモデルを選択すると、タイムラインのウィンドウ内に新規作成のボタンが出ます。
enter image description here

20

適当に名前をつけて保存
enter image description here

21

タイムラインのトラック上にアニメーションクリップを配置
再生時間を引き伸ばして決める
enter image description here

22

ループする場合は以下を変更
enter image description here

23

再生する
enter image description here