2D projectile motion calculation problem and passing different variables
Hey everyone,
I am a bit stuck here because I am newbie in Unity. So, I am making a turn based game where player shoots ball at the enemy and then enemy shots back. It is based on real projectile motion formulas. Point of the game is that student calculates angle or speed based on one that is missing (e.g. I am showing him always distance + one of these two: angle or speed). He should do calculation on paper and then put the correct value in the input field and then if all this taken is right, ball will hit the target (enemy). Following method gives the right curve and all based on angle and speed that I input.
I don't know how to construct a method that would calculate speed for angle of 89 degrees and for angle of 45 degrees to get maximum and minimum required speed to hit target at distance X. Because if I can store somewhere min and max, I know if I offer student some distance X and an angle that there is a speed calculation that is possible to hit the target. For angle I already know that because I know that angle must be more then 1 and less then 90 degrees and there is theoretical speed to hit target at any distance.
Blockquote
public void Shoot(float angle, float speed){
Xdistance= P2.transform.position.x - P1.transform.position.x; //player two transfor.pos.x - player one trans.position.x
AngRad= Mathf.Deg2Rad * angle;
float maxDistance = (speed* speed* Mathf.Sin(2 * AngRad) / gravity);
Vx = speed * Mathf.Cos(AngRad);
Vy = speed * Mathf.Sin(AngRad);
GameObject cloneGrude = Instantiate(snowBall, spawnerPosP1, Quaternion.identity) as GameObject;
Rigidbody2D clonerb = cloneGrude.GetComponent<Rigidbody2D>();
clonerb.velocity = new Vector2(Vx, Vy);
}
Blockquote
Your answer
Follow this Question
Related Questions
Cannot get my double jump to work (2D) , 0 Answers
The ban on going beyond the edge collider 0 Answers
Transform.position in 2d game or better way to move player working with colliders. 1 Answer
How do I get a ball to bounce inside of a circle? 1 Answer
How to set child gameobject rotation over the center of parent gameoject? 0 Answers