- Home /
Rigidbody.position freezes game
I'm attempting to program a script so that when my player enters a cube, he is teleported to the map spawnpoint. Everything works fine when I have a debug text in the code, but the moment I use rigidbody.position and touch the cube, the game freezes. I'm using Unity 5.1.2f1
using UnityEngine;
using System.Collections;
public class DeathManager : MonoBehaviour {
private Rigidbody rb;
//Start the code
void Start () {
rb = GetComponent <Rigidbody> ();
}
//Detect player entering void
void OnTriggerEnter (Collider other) {
if (other.tag == "Void") {
Die();
}
}
//Move player to save point
public void Die() {
if (Savestate.active.progress == 1) {
rb.position = new Vector3(10, 51, 10);
}
}
}
Edit Overview #1: Fixed code to be the actual script, added unity version
I edited the code to show the start function, it didn't copy at first for some reason
Sorry, It might me stupid comment but most of the time the normal mistake done by we peoples is We are doing some where Time.TimeScale = 0;
But we forget to make it 1 again.. If you are doing timeScale 0 then do check in "Edit> Projoect Setting > Time" that it is going back to 1 again.
Answer by 14ercooper · Aug 13, 2015 at 02:29 PM
I managed to solve this thanks to beau101023 and Eno Khaon!
It wasn't an issue with this script, is was an infinite loop in Savestate.active; so that every time you call it, it gets caught in a loops creating itself over and over again.
I believe Eno $$anonymous$$haon was the one who actually solved your problem.
$$anonymous$$eant to put both of you in there. $$anonymous$$y computer has been messing up my Unity Answers posts.
Answer by beau101023 · Aug 13, 2015 at 01:16 AM
You might want to move the whole GameObject to the spawn point. What version of Unity are you using?
Also, where is the reference to the rigidbody itself?
Does it freeze if you comment out just that particular line? Rather, if you don't try to move the object, but leave everything else, does it still freeze on you?
Then I would assume that it's not your attempts to move the object resulting in it freezing, but something else.
Usually, something like an infinite loop might cause Unity to freeze, but at the very least, there aren't any loops at all in the script example provided.
So, the next thing to try, then, if it's likely associated with this script still, would be to comment out the line calling the "Die()" function and see if it still freezes. If it does, it's possible it's not actually associated with this script.
I commented out the line calling Die() and the game no longer froze.
Your answer
Follow this Question
Related Questions
Freeze (lock) FPS position while still able to 'look around' 0 Answers
Does Rigidbody.freezRotation allow transform.Rotate ? 1 Answer
Stop moving rigidbody but don't stop rotating 1 Answer
Rigidbody question 1 Answer
to stop a rigidbody for a moment (works like a pause, only it's only for this object) 1 Answer