Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kfchristian15 · Feb 03, 2015 at 07:30 AM · c#spawnscriptingbasicsrespawncheckpoint

Checkpoint script problem

So I'm making a checkpoint script with empties in the game that are represented by GameObjects spawn, checkpoint1, checkpoint2, etc. The player respawns at the checkpoint, however they get stuck there and they can't move or fall. I checked with my teacher and they couldn't find exactly what the problem was either. I'm thinking that maybe the player is somehow snapping to the empty and being pinned there, as the movement script still functions, but the player doesn't move. Please let me know if you think you know what the problem could be, any input is appreciated. Many thanks!

bool alive=true; Vector3 spawnPoint;
int numberDeaths; public GameObject playerExplosion; float timer; int checkpointNumber; public GameObject checkpoint1; public GameObject checkpoint2; public GameObject spawn; bool death; Renderer[] playerMesh; public float offset; public GameObject mesh;

 void Start()
 {
     checkpointNumber=0;
     alive=true;
     death=false;
     GameObject spawnObject = spawn;
     spawnPoint = spawnObject.transform.position;
 }

 void Update () 
 {
     //playerMesh = GetComponentsInChildren <Renderer>(renderer.enabled);
     if (death)
     {
         if (checkpointNumber==0)
         {
             if (alive)
             {
                 GameObject spawnObject = spawn;
                 transform.position=spawnPoint;
                 spawnPoint = spawnObject.transform.position;
                 death=false;
                 timer=0;
                 collider.enabled=true;
             }
             if (!alive)
             {
                 timer += Time.deltaTime;
             }
             if (timer > 1.3 && !alive) {
                 GameObject spawnObject = spawn;
                 spawnPoint = spawnObject.transform.position;
                 transform.position=spawnPoint;
                 alive=true;
                 timer=0;
                 death=false;
                 collider.enabled=true;
             }

         }
     }
     if (checkpointNumber==1)
     {
         if (alive)
         {
             GameObject spawnObject = checkpoint1;
             transform.position=spawnPoint;
             spawnPoint = spawnObject.transform.position;
             death=false;
             collider.enabled=true;
         }
         if (!alive)
         {
             timer += Time.deltaTime;
         }
         if (timer > 1.3 && !alive) {
             GameObject spawnObject = checkpoint1;
             transform.position=spawnPoint;
             spawnPoint = spawnObject.transform.position;
             collider.enabled=true;
             death=false;
             alive=true;
             timer=0;
         }
     }
     if (checkpointNumber==2)
     {
         if (alive)
         {
             GameObject spawnObject = checkpoint2;
             transform.position=spawnPoint;
             spawnPoint = spawnObject.transform.position;
             death=false;
             collider.enabled=true;
         }
         if (!alive)
         {
             timer += Time.deltaTime;
         }
         if (timer > 1.3 && !alive) {
             GameObject spawnObject = checkpoint2;
             transform.position=spawnPoint;
             spawnPoint = spawnObject.transform.position;
             collider.enabled=true;
             alive=true;
             timer=0;
             death=false;
         }
     }
 }
 void OnTriggerEnter (Collider other)
 {
     if (other.tag == "checkpoint")
     {
         checkpointNumber=checkpointNumber +1;
         other.gameObject.collider.enabled =false;
     }
 }
 void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == "death") 
     {
         death=true;
         numberDeaths=numberDeaths +1;
     }
     if (collision.gameObject.tag == "boom") 
     {    
         Instantiate (playerExplosion, transform.position, transform.rotation);
         alive=false;
         death=true;
         numberDeaths=numberDeaths +1;
         mesh.SendMessage ("RenderStatus");
         collider.enabled=false;
             
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Kriogenic · Feb 06, 2015 at 02:32 AM

One problem could be that the if(death) statement at beginning of update is ONLY around checkpoint 0 and none of the others. so the other checks are happening even when you are not in death state.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kfchristian15 · Feb 06, 2015 at 03:23 AM 0
Share

Thanks for your suggestion, that did fix a lot of the problems. However I still have a problem where I respawn at the previous checkpoint once before respawning at the new checkpoint. Any ideas why that could be the case?

avatar image Kriogenic · Feb 06, 2015 at 03:27 AM 0
Share

That I think has to do with this.

 transform.position=spawnPoint;
 spawnPoint = spawnObject.transform.position;

you are setting the position first and then changing the spawnPoint. try swapping those 2 lines around each time it appears.

avatar image kfchristian15 · Feb 06, 2015 at 03:36 AM 0
Share

Thank you so much, that did it. I thought everything in an if was called at same time, but I see how order can make a difference. Thanks for solving my problem!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Help with SendMessage 1 Answer

Why doesnt my checkpoint system work? 1 Answer

Moving Player After Falling Certain Distance [Beginner/C#] 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges