111111
1111111111
特别好哈哈哈哈
OnCollisionEnter
小球装入大炮 OnTriggerEnter
MovePosition
获取该obj的this.transform, this.GetCompoent<Rigidbody>();
刹车处理
rigid.velocity = Vector3.Lerp(rigid.velocity, new Vector3 (0, rigid.velocity.y, 0) , 0,2f);
private bool brake
brake = Input.GetKey(KeyCode.Space);
按下空格 刹车
update 里面接受键盘wsad的input
dir = Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
Is Kinematic 如果勾选了就是绝对静止
Interpolate 差值, 使得物体的移动更加的自然,但是弊端就是可能与物体的渲染不同步,则会看到抖动
5.平台移动MovePositon();方法
private Transform m_Plate;
private Rigidbody m_plate;
private int direction=1;
public float speed=1;
void Start(){
m_Plate=this.transform;
m_plate=GetComponent<Rigidbody>();
}
void Update(){
if(m_Plate.position.x>=5&&direction>0){
direction=-1;
else if(m_Plate.position.x<=-6&&directon<0){
direction=1;
}
void FixedUpdate(){
m_Plate.MovePositon(vector3.x*speed*direction*Time.Fixeddatetime);
5.陷阱三
private Rigidbody m_cycle;
void Start(){
m_cycle=this.GetComponent<Rigidbody>();
}
void FixdeUpdate(){
m_cycle.angularVelocity=vector3.up*speed;
}
4.陷阱二
public speed;
void onTriggerEnter(collider other)//other指碰撞过来的物体
{
other=GameObject.GetComponent<Rigidbody>();
other.AddForce(vector3.up*speed,ForceMode.Impulse);
}
3.陷阱一
public Rigidbody[] m_Rigidbody;
public float speed;
public Rigidbody m_Plate;
public Rigibody m_plate;
private bool isFinish;
private bool VelocityEnough(){
for(int i=0;i<m_Rigidbody.length;i++){
if(m_Rigidbody[i].angularvelocity.y>5){
return=true;
}
else{
return=false;
}
}}
void Update(){
if(VelocityEnough&&!isFinish){
isFinish=false;
for(int i=0; i<m_Rigidbody.length;i++){
m_Rigidbody[i].gameObject.SetActive(false);
}
m_Plate.inkincit=false;
else if(isFinish){
m_Plate.velocity=vector3.up*speed;
m_plate.gameobject.SetActive(true):
}
2.小球转动 AddTorque();方法
private int que;//旋转方向
pulic float force=10f;//旋转角度
void Update(){
if(Input.GetKey(KeyCode.Q)){
que=-1;
}
else if(Input.GetKey(KeyCode.E)){
que=1;
}
else{
que=0;
}
}
void ForceUpdate(){
if(!stop){
Ball_Rigidbody.AddForce(direction*force,ForceMode.Force);
Ball_Rigidbody.Torque(vector3.up.*que*force;
}
else{
Ball_Rigidbody.velocity=vector3.Lerp(Ball_Rigidbody.velocity,new vector3(0,Ball_Rigidbody.velocity.y,0),20;
}
//摄像机跟踪 方法一
private Transform Tan_Camera;
public Transform Tan_ball;
public vector3 dir;
void Start(){
Tan_Camera=this.Transform;//获取组件
Tan_ball=GameObject.GetComponent<Transform>();//获取组件
dir=new vector3(0,3,-5);
}
//摄像机的跟踪
void ForceUpdate(){
Tan_Camera.position=Tan_ball.position+dir;
Tan_Camera.LookAt(Tan_Ball);
}
//摄像机跟踪方法二 脚本挂于小球上
private Tansform Camera;
private Tansform Ball;
public vector3 dir;
void Start(){
Camera=GameObject.GetComponent<Transform>();
Ball=this.transform;
dir= Mathf.Abs(Camera.position-Ball.position);
}
void ForceUpdate(){
Camera.position=Ball.position+dir;
Camera.LookAt(gameObject);
}
1.小球移动 AddForce();方法
private Rigidbody Ball_Rigidbody;
public float force=6f;
private bool stop;
void Start(){
Ball_Rigidbody=GetComponent<Rigidbody>();
}
void Update(){
//获取按键,前后左右移动
private Vector3 direction=new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
stop=Input.GetKey(KeyCode.Space));
}
void ForceUpdate(){
if(!stop){
Ball_Rigidbody.AddForce(direction*force,ForceMode.Force);
}
else{
Ball_Rigidbody.velocity=vector3.Lerp(Ball_Rigidbody.velocity,new vector3(0,Ball_Rigidbody.velocity.y,0),20;
}
力量模式:
ForceMode.acceleration:只关系加速度
ForceMode.force:关系质量的
ForceMode.impulse:脉冲力,考虑质量,是一瞬间的爆发力
ForceMode.velocitychange:忽略质量,只关系速度