そのままアニメーションを適用すると勝手に歩いていっちゃうのを防ぐ方法。
適用したオブジェクトのAnimator→Apply Root Motionのチェックを外す。
これで移動力を持つアニメを適用しても移動しなくなる。
参考:NavmeshのAI経路探索とAnimatorのアニメーションを連動させる#Unity
animator.SetFloat("Speed",
agent.velocity.sqrMagnitude);
マウスの中ボタンドラッグ(そんなの聞いてない)
Skeleton.GetComponent(Animator).Play("Base Layer.idle", -1, 0.0f);
var Player : GameObject;
Player = GameObject.Find("Dimples").gameObject;
Debug.Log(Player.GetComponent(Animator).GetCurrentAnimatorStateInfo(0).normalizedTime);
var Player : GameObject;
Player = GameObject.Find("Dimples").gameObject;
if(Player.GetComponent(Animator).GetCurrentAnimatorStateInfo(0).IsName("idle")
== true){
Debug.Log("idle");
}
else
if(Player.GetComponent(Animator).GetCurrentAnimatorStateInfo(0).IsName("attack1")
== true){
this.GetComponent(Rigidbody).AddForce(Vector3(0.0f, 10.0f, 0.0f),
ForceMode.Impulse);
Debug.Log("attack1");
}
カッコイイモーションをインポートして、アニメーターに設定してもうまく動かない場合
何も考えずにモーションを設定するとズボっとはまったりする
・修正したいアニメーションをEdit
・[Rig]の[Animation Type]を[Humanoid]に変更して[Apply]
※でもなんだかおかしなモーションになってる場合もある?※
・ボーンを辿って、動くボーンにコライダを付与
・Add Component →Physics→お好きなコライダー(球なり柱なり)
・こんなかんじ
この当たり判定が実際に当たったかどうかチェックするにはオブジェクト名でしたりタグでしたりできる。
オブジェクト名でチェックするパターン
function OnCollisionEnter(collision : Collision){
if(collision.gameObject.name == "Floor"){
Debug.Log("Hit the floor");
}else if(collision.gameObject.name == "Wall"){
Debug.Log("Hit the wall");
}
}
※なんにせよコライダーと一緒にrigidbory付けとかないと判定されないので注意!!※