hello,everyone. I creat a move script for my protagonist.
var MousePoAlpha : Vector2;
var MousePoOmega : Vector2;
static var moveYN : boolean = true;
function Update () {
if(transform.position.z != 0){
transform.position.z=0;
}
if(moveYN==true){
transform.rotation = Quaternion.LookRotation(rigidbody.velocity);
if(Input.GetMouseButtonDown(0)){
MousePoAlpha=Input.mousePosition;
}
if(Input.GetMouseButtonUp(0)){
MousePoOmega=Input.mousePosition;
rigidbody.velocity=Vector3(MousePoOmega.x-MousePoAlpha.x,MousePoOmega.y-MousePoAlpha.y,0)/5;
}
rigidbody.velocity=rigidbody.velocity*0.999; // Slow deceleration.
}
if(moveYN==false&&Input.GetMouseButtonUp(0)){
transform.rigidbody.velocity =transform.TransformDirection( Vector3( 0, 20, 0) );
}
}
This is a 2DGame. I drog my protagonist to a direction and it will go.
My teacher say this is not good way to move. He say we need affiliate a "time". But I don't kown where we need affiliate this "time".
And it have a problem when speed was too high... It will through other Object!(No collision)
Because this is a phone game so I'm not willing to consume too many resources. So I think limit speed is a good way.
Have any API can limit speed about velocity?
Thank you.