博客列表 >刚体Rigidbody.MoveRotation控制物体旋转

刚体Rigidbody.MoveRotation控制物体旋转

龍__遇见彩虹的博客
龍__遇见彩虹的博客原创
2017年12月02日 16:36:064050浏览

Rigidbody.MoveRotation

public void MoveRotation(Quaternion rot);   


Description:

Rotates the rigidbody to rotation.

Use Rigidbody.MoveRotation to rotate a Rigidbody, complying with the Rigidbody's interpolation setting.

If Rigidbody interpolation is enabled on the Rigidbody, calling Rigidbody.MoveRotation will resulting in a smooth transition between the two positions in any intermediate frames rendered. This should be used if you want to continuously rotate a rigidbody in each FixedUpdate.

Set Rigidbody.rotation instead, if you want to teleport a rigidbody from one rotation to another, with no intermediate positions being rendered.


例子:

using UnityEngine;
using System.Collections;
public class DemoController : MonoBehaviour {

    public Rigidbody player;
    public Transform enemy;
    private float speed = 10;
    
    private void Update()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            Vector3 dir = enemy.position - player.position;
            dir.y = 0;
            Quaternion target = Quaternion.LookRotation(dir);
            player.transform.rotation = Quaternion.Slerp(player.rotation, target, Time.deltaTime);
        }
    }
}


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议