博客列表 >刚体Rigidbody.MovePosition控制物体移动

刚体Rigidbody.MovePosition控制物体移动

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

Rigidbody.MovePosition

public void MovePosition(Vector3 position);


Description:

Moves the rigidbody to position.

Use Rigidbody.MovePosition to move a Rigidbody, complying with the Rigidbody's interpolation setting.

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

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


例子:

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

    public Rigidbody cube1;
    private float speed = 20;
    
    private void Update()
    {
        //cube1.position = cube1.transform.position + Vector3.forward * Time.deltaTime * speed;
        cube1.MovePosition(cube1.transform.position + Vector3.forward * Time.deltaTime * speed);//MovePosition方法使物体移动更平滑
    }
}


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议
JonnyZhu2017-12-02 16:06:251楼
通过刚体组件进行移动可以减少更多的性能消耗!