人物在碰到物体的时候没有跳跃,直接穿过去了。
这是代码
public class Player : MonoBehaviour
{
private Animator anim;
private int speedRotateID = Animator.StringToHash("SpeedRotate");
private int speedZID = Animator.StringToHash("SpeedZ");
private int VaultID = Animator.StringToHash("Vault");
private Vector3 matchTarget = Vector3.zero;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
anim.SetFloat(speedZID, Input.GetAxis("Vertical") * 4.1f);
anim.SetFloat(speedRotateID, Input.GetAxis("Horizontal") * 126);
bool isVault = false;
if (anim.GetFloat(speedZID) > 3 && anim.GetCurrentAnimatorStateInfo(0).IsName("Locomotion"))
{
RaycastHit hit;
if (Physics.Raycast(transform.position + Vector3.up * 0.3f, transform.forward, out hit, 4.5f))
{
if (hit.collider.tag == "Obstacle")
{
if (hit.distance > 3)
{
Vector3 point = hit.point;
point.y = hit.collider.transform.position.y + hit.collider.bounds.size.y+0.1f;
matchTarget = point;
isVault = true;
}
}
}
}
anim.SetBool(VaultID, isVault);
if (anim.GetCurrentAnimatorStateInfo(0).IsName("Vault"))
{
anim.MatchTarget(matchTarget, Quaternion.identity, AvatarTarget.LeftHand, new MatchTargetWeightMask(Vector3.one, 0), 0.38f, 0.5f);
}
}
}
然后之前没有用Matchtarger之前人物是可以跳跃的,就是之前这个代码
void Update()
{
anim.SetFloat(speedZID, Input.GetAxis("Vertical") * 4.1f);
anim.SetFloat(speedRotateID, Input.GetAxis("Horizontal") * 126);
bool isVault = false;
if (anim.GetFloat(speedZID) > 3 )
{
RaycastHit hit;
if (Physics.Raycast(transform.position + Vector3.up * 0.3f, transform.forward, out hit, 4.5f))
{
if (hit.collider.tag == "Obstacle")
{
if (hit.distance > 3)
isVault = true;
}
}
}
anim.SetBool(VaultID, isVault);
我qq 191401317