3D游戏编程作业六打飞碟改进-创新互联
前言
网页标题:3D游戏编程作业六打飞碟改进-创新互联
网站路径:http://lswzjz.com/article/dhjoch.html
这次的任务是实现物理学运动,结果我发现在上次作业中我全给实现了。
所以这次只要简单实现adapter就行了。
model脚本:github
原版代码:上次作业
我的adapter是实现物理学跟运动学两种运动的接口。
1.原版运动public void setdisk(int sp,System.Random r){//改变飞碟速度
int rp = r.Next()%position.GetLength(0);
disk.transform.position = position[rp];
Rigidbody rigidbody;
rigidbody = disk.GetComponent();
//启动刚体
rigidbody.WakeUp();
rigidbody.useGravity = true;
//添加瞬间力
float disksp = 1;
for(int i = 1;i
2.使用adapterpublic void setdisk(int sp,System.Random r){//改变飞碟速度
int rp = r.Next()%position.GetLength(0);
disk.transform.position = position[rp];
Rigidbody rigidbody;
rigidbody = disk.GetComponent();
//启动刚体
rigidbody.WakeUp();
float disksp = 1;
for(int i = 1;i
adapter类public class Adapter: System.Object{public Kinematicsn kinematicsn;
public Physis physis;
GameObject disk;
public Adapter(GameObject disk){this.disk = disk;
kinematicsn = disk.AddComponent() as Kinematicsn;
physis = disk.AddComponent() as Physis;
kinematicsn.setdisk(disk);
physis.setdisk(disk);
}
public void move(int mode,Vector3 force,Vector3 rota){if(mode == 1){physis.move(force,rota);
}
else kinematicsn.move(force);
}
public void stop(){kinematicsn.stop();
}
}
物理学类public class Physis:MonoBehaviour{GameObject disk;
public void setdisk(GameObject disk){this.disk = disk;
}
public void move(Vector3 force,Vector3 rota){Rigidbody rigidbody;
rigidbody = disk.GetComponent();
rigidbody.useGravity = true;
//添加瞬间力
rigidbody.AddForce(force*Random.Range(5, 8)/5, ForceMode.Impulse);
//添加旋转力
rigidbody.AddTorque(rota * 10);
}
}
运动学类public class Kinematicsn:MonoBehaviour{GameObject disk;
Vector3 speed;
float gra = -10.0f;
int work = 0;
public void setdisk(GameObject disk){this.disk = disk;
}
public void move(Vector3 force){speed = force;
work = 1;
}
public void stop(){work = 0;
}
void Update(){if(work == 1){disk.transform.position += speed*Time.deltaTime;
speed.y += gra*Time.deltaTime;
}
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
网页标题:3D游戏编程作业六打飞碟改进-创新互联
网站路径:http://lswzjz.com/article/dhjoch.html