Before sharing the "golden finger" implementation of the parabola between two points, then a friend asked me, in general, will give the speed, how to simulate the natural trajectory.
I hear this is not very easy to achieve, according to the previous formula, two points between the time is constant, the trajectory is determined, that is, the average speed is constant.
Then in turn, at a given average speed, and then by distance/velocity, the time can be drawn, then the trajectory is determined.
OK, I don't have much nonsense, just on the code:
usingUnityengine;usingSystem.Collections; Public classpaowuline:monobehaviour{ Public floatShotspeed =Ten; Private floatTime =1;//represents the length of time from point A to B PublicTransform Pointa;//Point A PublicTransform POINTB;//Point B Public floatg =-Ten;//Gravitational Acceleration//Use this for initialization PrivateVector3 speed;//Initial velocity Vector PrivateVector3 Gravity;//Gravity vector PrivateVector3 Currentangle; voidStart () { time= Vector3.distance (pointa.position, pointb.position)/Shotspeed; Transform.position= Pointa.position;//Place The object at point a//calculate the initial velocity by a formulaSpeed =NewVector3 ((pointb.position.x-pointa.position.x)/Time , (POINTB.POSITION.Y-POINTA.POSITION.Y)/Time-0.5f* g * time, (POINTB.POSITION.Z-POINTA.POSITION.Z)/Time ); Gravity= Vector3.zero;//Gravity initial velocity is 0 } Private floatDTime =0; //Update is called once per frame voidfixedupdate () {gravity.y= G * (dTime + = time.fixeddeltatime);//V=at//Analog DisplacementTransform.position + = (speed + Gravity) *Time.fixeddeltatime; Currentangle.x=-mathf.atan ((speed.y + gravity.y)/speed.z) *mathf.rad2deg; Transform.eulerangles=Currentangle; }}
This time directly to add the angle, like friends can test their own.
Time-constant two-point trajectory: http://www.cnblogs.com/jqg-aliang/p/4806017.html
General parabolic trajectory: http://www.cnblogs.com/jqg-aliang/p/4806002.html#3292517
Well, the simple implementation algorithm for Angry Birds, bows and arrows is almost enough. I've been studying the missile flight algorithm for a long time, and there's a new direction,
The use of parabolic simulations of dynamic trajectories will have a more realistic and natural effect. Welcome attention.
Unity Parabola, motion trajectory at average speed