void predictPath() { var go = Fsm.GetOwnerDefaultTarget(gameObject); if (go == null) { return; } tp.Predict3D(startPosition.Value, velocity.Value, gravity.Value, linearDrag.Value); }
///<summary> ///Given these values, get a RaycastHit of where the trajectory collides with an object, /// without needing to create an instance of the class or use it as a component. ///</summary> public static RaycastHit GetHitInfo3D(Rigidbody rb, float accuracy = 0.985f, int iterationLimit = 150, bool stopOnCollision = true) { GameObject tObj = new GameObject(); tObj.name = "TrajectoryPredictionObj"; TrajectoryPredictor pt = tObj.AddComponent <TrajectoryPredictor>(); pt.accuracy = accuracy; pt.iterationLimit = iterationLimit; pt.stopOnCollision = stopOnCollision; pt.Predict3D(rb); Destroy(tObj); return(pt.hitInfo3D); }
///<summary> ///Given these values, get an array of points representing the trajectory in 3D without needing to create an instance of the class or use it as a component. ///</summary> public static Vector3[] GetPoints3D(Rigidbody rb, float accuracy = 0.985f, int iterationLimit = 150, bool stopOnCollision = true) { GameObject tObj = new GameObject(); tObj.name = "TrajectoryPredictionObj"; TrajectoryPredictor pt = tObj.AddComponent <TrajectoryPredictor>(); pt.accuracy = accuracy; pt.iterationLimit = iterationLimit; pt.stopOnCollision = stopOnCollision; pt.Predict3D(rb); Destroy(tObj); return(pt.predictionPoints.ToArray()); }
///<summary> ///Given these values, get a RaycastHit of where the trajectory collides with an object, /// without needing to create an instance of the class or use it as a component. ///</summary> public static RaycastHit GetHitInfo3D(Vector3 startPos, Vector3 velocity, Vector3 gravity, float linearDrag = 0f, float accuracy = 0.985f, int iterationLimit = 150, bool stopOnCollision = true) { GameObject tObj = new GameObject(); tObj.name = "TrajectoryPredictionObj"; TrajectoryPredictor pt = tObj.AddComponent <TrajectoryPredictor>(); pt.accuracy = accuracy; pt.iterationLimit = iterationLimit; pt.stopOnCollision = stopOnCollision; pt.Predict3D(startPos, velocity, gravity, linearDrag); Destroy(tObj); return(pt.hitInfo3D); }
///<summary> ///Given these values, get an array of points representing the trajectory in 3D without needing to create an instance of the class or use it as a component. ///</summary> public static Vector3[] GetPoints3D(Vector3 startPos, Vector3 velocity, Vector3 gravity, float linearDrag = 0f, float accuracy = 0.985f, int iterationLimit = 150, bool stopOnCollision = true, int rayCastMask = -1) { GameObject tObj = new GameObject(); tObj.name = "TrajectoryPredictionObj"; TrajectoryPredictor pt = tObj.AddComponent <TrajectoryPredictor>(); pt.raycastMask = rayCastMask; pt.accuracy = accuracy; pt.iterationLimit = iterationLimit; pt.checkForCollision = stopOnCollision; pt.Predict3D(startPos, velocity, gravity, linearDrag); Destroy(tObj); return(pt.predictionPoints.ToArray()); }
void LateUpdate() { //set line duration to delta time so that it only lasts the length of a frame tp.debugLineDuration = Time.unscaledDeltaTime; //tell the predictor to predict a 3d line. this will also cause it to draw a prediction line //because drawDebugOnPredict is set to true tp.Predict3D(launchPoint.position, launchPoint.forward * force, Physics.gravity); //this static method can be used as well to get line info without needing to have a component and such //TrajectoryPredictor.GetPoints3D(launchPoint.position, launchPoint.forward * force, Physics.gravity); //info text stuff if (infoText) { //this will check if the predictor has a hitinfo and then if it does will update the onscreen text //to say the name of the object the line hit; if (tp.hitInfo3D.collider) { infoText.text = "Hit Object: " + tp.hitInfo3D.collider.gameObject.name; } } }