https://blog.csdn.net/wdw5945/article/details/48862621
transform.position 与Rigidbody.position的同步问题导致我花了一整天调了一个不存在的问题。原本我以为设置rigibody的坐标能直接影响GameObject的transform的坐标。因为看起来是这样的。但今天的测试发现,如果你只设置了Rigidbody的position,那么在这一帧里,程序获取到的transform的position是没有同步的。因为这个问题,影响了我的控制逻辑,白白花了一天时间在调一个不存的的物理公式问题!只想说一个F开头的单词!!
t/wdw5945/article/details/48862621
Rigidbody.position/rotation更新测试
https://www.cnblogs.com/hont/p/5217800.html
Rigidbody.position/rotation主要提供在下一个物理步之前更新物理位置,一般用于SweepTest这样的接口
那么测试一下会不会修改掉transform.position的值
测试结果:并不会立即改变transform.position,而会在下一个物理步执行时改变。如果手动改变transform.position/rotation不受影响
测试脚本:
using UnityEngine; public class RigidbodyStepTest : MonoBehaviour { public Rigidbody rigidbodyComponent; void OnEnable() { rigidbodyComponent.position = Vector3.zero; Debug.Log("OnEnable: " + transform.position + " frame count: " + Time.frameCount); } void FixedUpdate() { Debug.Log("FixedUpdate: " + transform.position + " frame count: " + Time.frameCount); } void Update() { Debug.Log("Update: " + transform.position + " frame count: " + Time.frameCount); } }
结果:
由于Unity物理的更新在FixedUpdate之后,而FixedUpdate调用在Update之前,故Update时值归0了
========================
Rigidbody.position 位置
http://www.manew.com/youxizz/2506.html
var position : Vector3
Description描述
The position of the rigidbody.
该刚体的位置。
This is similar to setting transform.position, however the position will only be applied to the transform at the end of the physics step. If you want to continously move a rigidbody or kinematic rigidbody use MovePosition and MoveRotation instead
这个类似设置transform.position,然而position只在物理步结束应用到变换。 如果你想连续移动一个刚体或运动学刚体,使用MovePosition和MoveRotation代替。