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 FreddieThePotato · Jun 02, 2015 at 11:20 AM · checkpoint

Checkpoints in a platformer

Sincere greetings ladies and gentlemen. I require a checkpoint system for my game in development, and I am completely new to unity so this is proving a little difficult. I am able to send the player back to the last checkpoint they touched without problems. The problem I have however is that it is also necessary for all of the enemies in the level to reset and return to their original positions, which I am clueless about doing. Any help or advice would be greatly appreciated. Thank you.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by redeemer · Jun 02, 2015 at 12:07 PM

If you only need to restore the positions at the last checkpoint, you could try the next approach :

  • Declare a variable in your enemy's script such as "lastCheckpointPos", you will update this var each time the player gets to a checkpoint.

  • Create a function to save that last position, such as "SaveLastCheckpointPos()", you have to call this function in all your enemies when the player reaches the checkpoint.

  • Create a function in that same script such as "RestoreLastCheckpointPos()", where you set the enemy's actual position to the "lastCheckpointPos"

  • And finally, when you set your player to reappear in the last checkpoint, you must call RestoreLastCheckpointPos() for all your enemies and there you go...

I assume you are controlling the return to the checkpoint in the player's script, I would add something like this in the player script or where you control the checkpoints :

 GameObject[] enemiesInScene;
     
 void Start() {
     
    enemiesInScene = GameObject.FindObjectsWithTag("Enemy");
     
 }
 
 //I assume you would have a funtion to set the player
 void RestoreToLastCheckpoint() {
 
    //Your code for repositioning the player last checkpoint
 
    foreach(GameObject enemy in enemiesInScene) enemy.GetComponent<EnemyScript>().RestoreLastCheckpointPos();
 
 }
 
 //I assume you would have a funtion to save the last checkpoint
 void SaveLastCheckpoint() {
 
    //Your code for saving the last checkpoint reached
 
    foreach(GameObject enemy in enemiesInScene) enemy.GetComponent<EnemyScript>().SaveLastCheckpointPos();
 
 }
 

And then in the enemy's script :

 Vector3 lastChekpointPos;
 
 void Start() {
 
    lastChekpointPos = transform.position;
 
 }
 
 public void SaveLastCheckpointPos() {
 
    lastChekpointPos = transform.position;
 
 }
 
 public void RestoreLastCheckpointPos() {
 
   transform.position = lastCheckpointPos;
 
 }


Hope this helps.

Comment
Add comment · Show 2 · 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 FreddieThePotato · Jun 02, 2015 at 02:06 PM 0
Share

Thank you very much, I appreciate the feedback.

avatar image redeemer · Jun 02, 2015 at 04:35 PM 0
Share

You're welcome and please don't forget to mark the answer as accepted if it helped you solve the problem. If on the other hand the answer does not apply for this case for any reasons we'll work on a different approach ;)

avatar image
0

Answer by santiandrade · Nov 19, 2015 at 12:28 PM

Hi! You can use my recent tutorial about the creation of a checkpoints system with Unity: https://santiandrade.github.io/Unity-Creating-a-checkpoints-system/

Good luck!

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Race checkpoint system small help please :) 1 Answer

How do I create a good Checkpoint system? 0 Answers

Checkpoint GUI enabled then disabled trouble 3 Answers

How do you make a respawn and checkpoint script? 0 Answers

how do I make smart checkpoints? 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