- Home /
Copter movement
At present I am trying to behavior some thing like following 2d game : Retry
Basically above game contains following type of movement. I have taken snapshot for that
I can't able to figure out starting point for this. Right now I am considering, I have to choose some point far from copter and based on that point rotate copter around that point.
I don't know whether I am right in this. So that I need some suggestion from your side because this type of movement I have seen first time in copter game.
Please give some suggestions and tips in this.
Answer by koray1396 · Nov 25, 2014 at 11:46 AM
not tested, but the following should work for the movement and rotation of the copter.
rotation = rotationSpeed * rotationSide //rotationSide > 0 for no rotation, 1 for counter-clockwise, -1 for clockwise.
transform.Rotate(Vector3.forward * rotation * Time.deltaTime);
transform.position += transform.right * Speed * Time.deltaTime;
How to decide rotationSide? Based on which parameter I have to decide this value?
you have to decide rotationSpeed and speed of the copter. you should assign rotationSide with your Input, like;
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow)){
rotationSide = 1;
}
//etc...
I am trying to develop game for android only. So I have only tap available for moving plane.
I think first you have to view copter's actual movement first. Then you give better answer.
ok... you really should figure out these yourself man. I don't know how Retry works, a simple touch system would be like this. If you touch right side of the screen, copter rotates clockwise, else, left side would rotate counterclokwise.
void DetectTouch(){
float rotationSide = 0f;
if(Input.touches.Length > 0){
for(int i = 0; i < Input.touches.Length; i++){
Vector2 tp = Camera.main.ScreenToViewportPoint(Input.GetTouch (i).position);
if(tp.x >= 0.5f){
rotationSide -= 1f;
} else {
rotationSide += 1f;
}
}
}
rotationSide = $$anonymous$$athf.Clamp (rotationSide, -1f, 1f);
rotation = rotationSpeed * rotationSide //rotationSide > 0 for no rotation, 1 for counter-clockwise, -1 for clockwise.
transform.Rotate(Vector3.forward * rotation * Time.deltaTime);
transform.position += transform.right * Speed * Time.deltaTime;
}
Thanks @koray1396, I have up vote your answer because I am getting something from it. There is no need to calculate rotationSide because I have to move only right side only. Value 1 to rotationSide works perfectly here.
Using your answer, I am near to correct behavior of copter. Just one thing remains, On touch first copter has to travel some what horizontal distance then start movement as per above coding but horizontal movement is some what slant in direction.
Please give final suggestion for this.