Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

GameObject get launched underneath the terrain when using AddForce

$
0
0
According to my script the car should be launched into the air and when it lands back on the ground it should resume its original track of the navmesh. **Sometimes** when another gameobject collides with this gameobject(car) the car gets launched into "the ground"( below the terrain (y = -223.32 to be exact) and then appears again and follows its orignal track of the navmesh. It is also worth noting this only happens on devices with a high fps like a pc or high-end android devices. On my phone (lower fps) everything works perfectly. Rigidbody rb; NavMeshAgent agent; void OnCollisionEnter (Collision other) { if(other.gameObject.CompareTag("Wrecking Ball") && time >= 1.0f) { time = 0; InvokeRepeating ("Timer", 1.0f, 0.5f); //pause navmesh oncollision agent.updatePosition = false; agent.Stop (); //effect of collision health = health - damage; rb.AddForce (new Vector3 (0, 15, 0), ForceMode.Impulse); transform.Rotate (35, 0, 0); //resume after 2 seconds InvokeRepeating("Resume",2.5f,0.1f); } void Resume() { //resume original track of car if (gameObject.transform.position.y <= 0.501 && health != 0) { agent.Warp (transform.position); //if using infinite scene another script is called for setting the correct track of the car if (SceneManager.GetActiveScene().name == "Infinite") { InfiniteAgent infiniteAgent = gameObject.GetComponent (); infiniteAgent.destPoint -= 1; } else { AgentScript agentScript = gameObject.GetComponent (); agentScript.destPoint -= 1; } agent.Resume (); agent.updatePosition = true; CancelInvoke (); } } void Timer() { //so the wrecking ball isn't destroying the car right away time += 1; }

Viewing all articles
Browse latest Browse all 1264

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>