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 Orggrim · Apr 16, 2012 at 05:11 PM · javasystemrespawnhowcheckpoint

Checkpoint system???

Hi, i recently got my map to respawn the player at a point when he dies(or hits a trigger), I wanted to put in checkpoints now so the player doesnt have to restart all the way at the beginning, so far i have this, courtesy of Aldo.

 var dest: Transform; // drag the destination object here
 var sound: AudioClip; // define a teleport sound, if you want
 
 function OnTriggerEnter(other: Collider){
   if (other.tag == "Player"){
     // move the player and align it to the dest object:
     other.transform.position = dest.position;
     other.transform.rotation = dest.rotation;


I get the logic behind how to do it, just not sure about the code

if(player hits trigger)

{

change dest to "new trigger object here"

}

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Piflik · Apr 16, 2012 at 05:37 PM

I have an object for spawning my player. It writes its position in the character's main script and when the player dies, he is moved to that position. Changing that position would be the simple matter of writing the new object's position in the same location, when the player enters the trigger.

 function OnTriggerEnter(item : Collider) {
     if(item.tag == "Player")
         item.GetComponent("PlayerScript").startPos = transform.position;    
 }

It is a different script than yours, but so far it works in my game...and you wouldn't have to store the destination object in every checkpoint ;)

If you want to keep the code you have, you would have to make something like this:

 var dest: Transform; // drag the destination object here

 function OnTriggerEnter(item : Collider) {
     if(item.tag == "Player")
         dest.position = transform.position;
 } 

Haven't tested this, so say if it doesn't work.

Comment
Add comment · Show 1 · 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 Orggrim · Apr 18, 2012 at 03:14 PM 0
Share

it didnt work, i messed around with it as well and I had no luck

avatar image
0

Answer by Alpha_Guac · Oct 30, 2015 at 09:12 PM

I used a collision event for I found the trigger event to be very specific in how the condition is met. here's some functions that I used and they're pretty basic.

public class Checkpoint : MonoBehaviour { Vector3 spawnlocation;

 void Start () 
 {
     var tran = this.GetComponent<Transform>();
     spawnlocation =new Vector3(tran.position.x,tran.position.y,0);
 }

 void OnCollisionEnter(Collision other)
 {
     var tran = this.GetComponent<Transform>();
     if (other.gameObject.name == "Player")
     {//Sends a message to the player to call the UpdateSpawn function giving it the spawnlocation  variable
         other.gameObject.SendMessage("UpdateSpawn", spawnlocation, SendMessageOptions.DontRequireReceiver);

//moves the checkpoint out of the way so it can't be collided with again tran.position = new Vector3(tran.position.x, tran.position.y, 1); } } }

Player: Vector3 Spawnpoint = new Vector3(0, 1, 0);

 void UpdateSpawn(Vector3 position)
 {
     Spawnpoint = position;
 }

This way the Player deals with the spawn location nothing else. I hope this helps you out

Comment
Add comment · Show 1 · 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 LearningWhileScrewing · Jun 15, 2016 at 10:35 AM -1
Share

thats c sharp not java script xd everybody else speaking about js and u c sharp xd

avatar image
0

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

I have just writen a post about it in my blog: https://santiandrade.github.io/Unity-Creating-a-checkpoints-system/

Regards!

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help with a checkpoint system 0 Answers

enable / disable particle system 1 Answer

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

Particle System rotate 2 Answers

My respawn system does not work 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