学习视频是b站上的来自程序员的暴击博主
- unity中刚体的作用
①会于场景中的模型物体发生碰撞;
②会受重力影响(到达场影边缘外,会下落)。 - 使用刚体移动物体
- 代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
{
private Rigidbody rigi;
public float speed=5.0f;
// Start is called before the first frame update
void Start()
{
rigi = this.GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
rigi.MovePosition(transform.position + Vector3.back * Time.deltaTime * speed);
}
}
- 代码效果
cube会一直往前走,直到从平面掉落。
- 刚体移动的方法
① Rigidbody. Moveposition( Vector3):使用刚体移动物体的位置。
使用刚体移动物体,物体是根据世界坐标系的方向移动的。
使用刚体移动物体,物体会触发物理相关的事件。
② Moveposition中的 Vector3要使用**“当前位置”+方向**的方式。
Transform. Position:属性当前物体的位置。