void Start(){ tp = gameObject.AddComponent<TrajectoryPredictor>(); tp.drawDebugOnPrediction = true; tp.accuracy = 0.99f; tp.lineWidth = 0.03f; tp.iterationLimit = 600; }
void Start() { if (UiManager.instance != null) { if (!UiManager.instance.DisabledScripts.Exists(mono => mono == this)) { UiManager.instance.AddSelfToDisabledList(this); } } tp = GetComponent <TrajectoryPredictor>(); originalRatationSpeed = 2f; rotationSpeed = originalRatationSpeed * senseivity; anim = GetComponent <Animator>(); col = GetComponent <CapsuleCollider>(); rig = GetComponent <Rigidbody>(); currentHealth = maxHealth; hpSlider = GameObject.Find("HealthSlider").GetComponent <Slider>(); UpdateHpSlider(); FindAndDisableRagdollParts(); InstantiateProps(); SetClosestWaypoint(); if (DataManager.instance.GetPlayerPrefsBool("SlingshotControl") != -1) // Updates movement control type { if (DataManager.instance.GetPlayerPrefsBool("SlingshotControl") == 1) { slingshotControl = true; } else { slingshotControl = false; } } }
void Start(){ tp = gameObject.AddComponent<TrajectoryPredictor>(); tp.predictionType = TrajectoryPredictor.predictionMode.Prediction2D; tp.drawDebugOnPrediction = true; tp.accuracy = 0.99f; tp.lineWidth = 0.025f; tp.iterationLimit = 300; }
void Start() { tp = gameObject.AddComponent <TrajectoryPredictor>(); tp.drawDebugOnPrediction = true; tp.accuracy = 0.99f; tp.lineWidth = 0.03f; tp.iterationLimit = 600; }
void Start() { tp = gameObject.AddComponent <TrajectoryPredictor>(); tp.drawDebugOnPrediction = true; tp.reuseLine = true; //set this to true so the line renderer gets reused every frame on prediction tp.accuracy = 0.99f; tp.lineWidth = 0.03f; tp.iterationLimit = 600; }
private void Awake() { TrajectoryPredictor trajectory = GetComponent <TrajectoryPredictor>(); trajectory.OnPredictionIterationStep += HandlePredictionGravity; rb = GetComponent <Rigidbody>(); rb.velocity = startVelocity; }
void Start() { tp = gameObject.AddComponent <TrajectoryPredictor>(); tp.predictionType = TrajectoryPredictor.predictionMode.Prediction2D; tp.drawDebugOnPrediction = true; tp.accuracy = 0.99f; tp.lineWidth = 0.025f; tp.iterationLimit = 300; }
///<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()); }
public override void OnEnter() { var go = Fsm.GetOwnerDefaultTarget(gameObject); tp = go.GetComponent <TrajectoryPredictor>(); if (!everyFrame.Value) { predictPath(); Finish(); } }
///<summary> ///Given these values, get a RaycastHit2D 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 RaycastHit2D GetHitInfo2D(Rigidbody2D 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.predictionType = predictionMode.Prediction2D; pt.Predict2D(rb); Destroy(tObj); return(pt.hitInfo2D); }
///<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, 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(rb); Destroy(tObj); return(pt.hitInfo3D); }
///<summary> ///Given these values, get an array of points representing the trajectory in 2D without needing to create an instance of the class or use it as a component. ///</summary> public static Vector3[] GetPoints2D(Rigidbody2D rb, 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.predictionType = predictionMode.Prediction2D; pt.Predict2D(rb); Destroy(tObj); return(pt.predictionPoints.ToArray()); }
///<summary> ///Given these values, get a RaycastHit2D 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 RaycastHit2D GetHitInfo2D(Vector3 startPos, Vector2 velocity, Vector2 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.predictionType = predictionMode.Prediction2D; pt.Predict2D(startPos, velocity, gravity, linearDrag); Destroy(tObj); return(pt.hitInfo2D); }
///<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) { 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.predictionPoints.ToArray()); }
///<summary> ///Given these values, get an array of points representing the trajectory in 2D without needing to create an instance of the class or use it as a component. ///</summary> public static Vector3[] GetPoints2D(Vector3 startPos, Vector2 velocity, Vector2 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.predictionType = predictionMode.Prediction2D; pt.Predict2D(startPos, velocity, gravity, linearDrag); 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, 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.hitInfo3D); }
void Launch() { if (!launchObjParent) { launchObjParent = new GameObject(); launchObjParent.name = "Launched Objects"; } GameObject lInst = Instantiate(objToLaunch); lInst.transform.SetParent(launchObjParent.transform); Rigidbody rbi = lInst.GetComponent <Rigidbody> (); lInst.transform.position = transform.GetChild(0).Find("LP").position; rbi.rotation = transform.GetChild(0).Find("LP").rotation; rbi.AddRelativeForce(new Vector3(Random.Range(-30f, 30f), Random.Range(-10f, 10f), Random.Range(forceRange.x, forceRange.y))); Renderer tR = lInst.GetComponent <Renderer>(); tR.material = Instantiate(tR.material) as Material; tR.material.color = RandomColor(); TrajectoryPredictor tp = lInst.GetComponent <TrajectoryPredictor>(); tp.lineStartColor = tR.material.color; tp.lineEndColor = tR.material.color; switch (Random.Range(0, 3)) { case 0: tp.lineTexture = lineTextures[0]; break; case 1: tp.lineTexture = lineTextures[1]; tp.textureTilingMult = 0.35f; tp.lineWidth = 0.2f; break; case 2: tp.lineWidth = 0.1f; break; } }
void HandlePredictionGravity(ref Vector3 currentIterationVel, Vector3 currentIterationPos, TrajectoryPredictor tpInstance) { currentIterationVel += GetGravForce(currentIterationPos); }
// This function is executed at each of our game frame void Update() { //if(Cursor.lockState != CursorLockMode.Confined) //Cursor.lockState = CursorLockMode.Confined; // keep confined in the game window //// Depreciated for UNITY 5_3 // Check the Day/Night Settings GameObject SunLight = GameObject.Find("Sun"); SunLight.GetComponent <Light>().intensity = currentLightSettings; // Turning on the moon when the light intensity goes down GameObject Moon = GameObject.Find("MoonCrescent"); GameObject SunHalo = GameObject.Find("SunHalo"); GameObject Pl1 = GameObject.Find("Point light_1"); GameObject Pl2 = GameObject.Find("Point light_2"); GameObject Pl3 = GameObject.Find("Point light_3"); if (currentLightSettings < 0.25) { SunHalo.GetComponent <SpriteRenderer>().enabled = false; // Turn off Sun SunHalo.GetComponent <SpriteRenderer>().enabled = false; Moon.GetComponent <SpriteRenderer>().enabled = true; // Turn on Moon Pl1.GetComponent <Light>().enabled = true; Pl2.GetComponent <Light>().enabled = true; Pl3.GetComponent <Light>().enabled = true; } else { SunHalo.GetComponent <SpriteRenderer>().enabled = true; // Turn on Sun Moon.GetComponent <SpriteRenderer>().enabled = false; // Turn off Moon Pl1.GetComponent <Light>().enabled = false; Pl2.GetComponent <Light>().enabled = false; Pl3.GetComponent <Light>().enabled = false; } // Find the player object playerObject = GameObject.FindGameObjectWithTag("Player"); realTrailObject = GameObject.FindGameObjectWithTag("RealTrail"); //Add a shortcut button for turning on the trajectory TrajectoryPredictor trajectoryScript01 = playerObject.GetComponent("TrajectoryPredictor") as TrajectoryPredictor; TrajectoryPredictor trajectoryScript02 = realTrailObject.GetComponent("TrajectoryPredictor") as TrajectoryPredictor; if (PlayerPrefs.GetString("DebuggerMode").Equals("True")) { //// For Player trajectoryScript01.drawDebugOnUpdate = true; trajectoryScript01.drawDebugOnPrediction = true; //// For Real Trail trajectoryScript02.drawDebugOnUpdate = true; trajectoryScript02.drawDebugOnPrediction = true; } else { bool ctrl = Input.GetKey(KeyCode.RightControl); bool alt = Input.GetKey(KeyCode.RightAlt); bool t = Input.GetKeyDown(KeyCode.T); if ((ctrl && alt && t) || (alt && ctrl && t)) { if (!pressedOnce) { pressedOnce = true; } else { pressedOnce = false; } } if (pressedOnce) { // For Player trajectoryScript01.drawDebugOnUpdate = true; trajectoryScript01.drawDebugOnPrediction = true; // For Real Trail trajectoryScript02.drawDebugOnUpdate = true; trajectoryScript02.drawDebugOnPrediction = true; } else if (!pressedOnce) { // For Player trajectoryScript01.drawDebugOnUpdate = false; trajectoryScript01.drawDebugOnPrediction = false; // For Real Trail trajectoryScript02.drawDebugOnUpdate = false; trajectoryScript02.drawDebugOnPrediction = false; } } // Check the Magnetism Properties and trail renderer properties NinjaScript ninjaScript = playerObject.GetComponent("NinjaScript") as NinjaScript; if (magnetismOn) { ninjaScript.magnetismOn = true; } else { ninjaScript.magnetismOn = false; } // Check the Trajectory Assistance Properties and trail renderer properties if (trajectoryAssistanceOn) { ninjaScript.trajectoryAssistanceOn = true; } else { ninjaScript.trajectoryAssistanceOn = false; } // Timer Game Object GameObject timerObject = GameObject.Find("Timer"); // Timer settings shown on top of the screen if (timeStarted == true && timePaused == false && timer > 1) { timer -= Time.deltaTime; elapsedTime += Time.deltaTime; //elapsedTime = totalGameTime * 60 - timer; int minutes = Mathf.FloorToInt(timer / 60F); int seconds = Mathf.FloorToInt(timer - minutes * 60); string niceTime = string.Format("{0:00}:{1:00}", minutes, seconds); timerObject.GetComponent <Text>().text = niceTime; } else if (timer <= 1 && timeStarted == true && timePaused == false && !calledOnce) { timeStarted = false; timePaused = true; // Show the Game Over Screen again but with Time Out wriiten // Enable Canvas section GameObject canvasObject = GameObject.Find("Canvas"); Instantiate(canvasObject); canvasObject.GetComponent <Canvas>().enabled = true; Image panelImage = canvasObject.GetComponentInChildren <CanvasRenderer>().GetComponent <Image>(); panelImage.color = new Color(0, 0, 0, 1); //newPanelColor; // Disable Game Over Image GameObject gameOverObj = GameObject.Find("GameOverImage"); gameOverObj.GetComponent <Image>().enabled = false; // Enable TimeOut Image Text TimeOutObj = GameObject.Find("TimeOutText").GetComponent <Text>(); TimeOutObj.enabled = true; // Disbale the restart button GameObject buttonRestart = GameObject.Find("ButtonRestart"); buttonRestart.GetComponent <Image>().enabled = false; buttonRestart.GetComponent <Button>().enabled = false; // Destroy the player first to remove any additional log GameObject player = GameObject.FindGameObjectWithTag("Player"); Destroy(player); playerIsAlive = false; // pause for 5 seconds and then destroy everything StartCoroutine(TimeUp(5)); } else if (timePaused) { timerObject.GetComponent <Text>().text = "PAUSED"; RectTransform rt = timerObject.GetComponent <RectTransform>(); rt.localPosition = new Vector2(35, 0); rt.localScale = new Vector2(0.60F, 0.60F); } //float playerYPosition = GameObject.FindWithTag("Player").transform.position.y; float playersXvelocity = GameObject.FindGameObjectWithTag("Player").GetComponent <Rigidbody2D>().velocity.x; float playersYvelocity = GameObject.FindGameObjectWithTag("Player").GetComponent <Rigidbody2D>().velocity.y; // Mouse button is down, but ninja isn't jumping/falling (its y velocity is zero) and the ninja is not charging if (Input.GetButtonDown("Fire1") && playersXvelocity == 0 && playersYvelocity == 0 && !isCharging && playerIsAlive && !timePaused) { // check if the real trail exist or not if (GameObject.FindWithTag("RealTrail") != null) { //Destroy(GameObject.FindWithTag("RealTrail")); GameObject.FindWithTag("RealTrail").transform.position = playerObject.transform.position; GameObject.FindWithTag("RealTrail").transform.rotation = playerObject.transform.rotation; //Debug.Log("realTrailObject.transform.position: " + realTrailObject.transform.position); } isCharging = true; // now the ninja will be charging } // Mouse button released and the ninja is charging but not jumping/falling (its y velocity is zero) if (Input.GetButtonUp("Fire1") && playersXvelocity == 0 && playersYvelocity == 0 && isCharging && playerIsAlive && !timePaused) { isCharging = false; // player is no longer charging so set the isCharging to false GameObject powerObject = GameObject.FindWithTag("Power"); // get the game object tagged as "Power" PowerScript script = powerObject.GetComponent("PowerScript") as PowerScript; // inside the object tagged as "Power", get PowerScript script GameObject player = GameObject.FindGameObjectWithTag("Player"); player.SendMessage("Jump", maxJumpForce * script.chargePowerSender); // find the object tagged as "Player" and send "Jump" message, with the proper force updateScore = true; // Set the updateScore to true because the player just jumped } }
private void Start(){ tp = GetComponent<TrajectoryPredictor>(); Hide(); }