unity 物体移动上坡

Vector3 destUp = Vector3.zero;

void Start()
{
    
}

void Update()
{
    
    Vector3 newup = transform.position;
  
    RaycastHit hit;
    if (Physics.Raycast(transform.position,Vector3.down,out hit))
    {

        newup.y = (hit.point + Vector3.up * 2.0f).y;
        destUp = hit.normal;

    }
    transform.position = newup;
    transform.up = Vector3.Slerp(transform.up, destUp, 5f * Time.deltaTime);



    
}

你可能感兴趣的:(unity 物体移动上坡)