2017-10-30 7 views
-1

私は生存ゲームを作っています...私はいくつかの動きをしましたが、今はキャラクターをジャンプさせて、その上にプラットフォームをつかみ、そのプラットフォームを歩いて...そしてまた私は泳ぐことを望む、私は野生のゼルダの呼吸でちょっと泳いでいるのを見た。モータスクリプト私のプレイヤーをユニティで泳ぐ、掴む、持ち上げる

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.AI; 

public class Jump : MonoBehaviour { 
private CharacterController jumpControl; 
private float gravity = 7f, jumpForce = 5f; 
private float verticalVelocity; 
NavMeshAgent agent; 
PlayerMotor motor; 

// Use this for initialization 
void Start() { 
    jumpControl = GetComponentInChildren<CharacterController>(); 
    agent = GetComponentInParent<NavMeshAgent>(); 
} 

// Update is called once per frame 
void FixedUpdate() { 

    if (jumpControl.isGrounded) { 
     verticalVelocity = -gravity * Time.deltaTime; 
     agent.enabled = true; 


     if (Input.GetMouseButtonDown (1)) { 
      agent.enabled = false; 
      verticalVelocity = jumpForce; 
      Vector3 moveVector = new Vector3 (0, verticalVelocity, 0); 
      jumpControl.Move (moveVector * Time.deltaTime); 
     } 

    } else { 
     verticalVelocity -= gravity * Time.deltaTime; 
     Vector3 moveVector = new Vector3 (0, verticalVelocity, 0); 
     jumpControl.Move (moveVector * Time.deltaTime); 
    } 

} 

}

その後:

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.AI; 

[RequireComponent(typeof(NavMeshAgent))] 
public class PlayerMotor : MonoBehaviour { 

Transform target; 
public NavMeshAgent agent; 
// Use this for initialization 
void Start() { 
    agent = GetComponent<NavMeshAgent>(); 

} 
void Update(){ 
    if (target != null) { 
     agent.SetDestination (target.position); 
     FaceTarget(); 
    } 
} 

public void MoveToPoint(Vector3 point){ 
    agent.SetDestination (point); 
} 

public void FollowTarget(Interactables newTarget){ 
    agent.stoppingDistance = newTarget.radius * .8f; 
    agent.updateRotation = false; 
    target = newTarget.interactionTransform; 
} 

public void StopFollowingTarget(){ 
    agent.stoppingDistance = 0f; 
    agent.updateRotation = true; 
    target = null; 

} 
void FaceTarget(){ 
    Vector3 direction = (target.position - 
transform.position).normalized; 
    Quaternion lookRotation = Quaternion.LookRotation (new Vector3 
(direction.x, 0, direction.z)); 
    transform.rotation = Quaternion.Slerp (transform.rotation, 
lookRotation, Time.deltaTime * 5f); 
} 
} 

答えて

0

1)まず、ダウンロードanimations.Youができるいくつかの水泳私はこれは私のジャンプスクリプトです

を助けが必要ください。一部を hereから入手してください。

2)これらのアニメーションをキャラクターのアニメーションコントローラーに追加します( )。アニメーションをヒューマノイドに変更してください。デフォルトでは になります。

3)必要に応じてアニメーションをトリガーします。

Myanimator.SetTrigger("animation trigger name"); 

4)のチェックを外しアニメーションコントローラに「ルートモーションを適用」と移動したい方の方向に 速度を追加します。

yourRigidBody.velocity = new Vector3 (0, yourRigidBody.velocity.y, speed); 

5)また、いくつかのハングアップのためのジャンプとグラブ機能の検索を追加したり、アニメーションを登るとプラットフォームの両側にトリガを追加し、OnTriggerEnter()

にこれらのアニメーションを呼び出すために
関連する問題