//获取控制方向值
float LRValue = Input.GetAxis("Horizontal") * Time.deltaTime * mLRSpeed;
float UDValue = Input.GetAxis("Vertical") * Time.deltaTime * mUDSpeed;
//保持Y轴不变,仅更新x和z轴
transform.position += new Vector3(LRValue, 0, UDValue);
//获取控制方向值
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis("Horizontal");
Vector3 translate = (new Vector3(h, 0, v) * Time.deltaTime) * mUDSpeed;
transform.Translate(translate);
1).position属于位置坐标,赋值坐标,则可以想象成物体直接瞬移到位置点。translate属于位置动作,赋值坐标,则可以想象成物体向位置点进行移动偏移过去,是个持续过程。
2).注意,通过translate函数进行位置挪移,他属于动作行为,就会受位置本身的rotation影响,而导致最终结果不符合预期。