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
1
Question by Orggrim · Apr 19, 2012 at 09:51 PM · spawnrespawnkillcheckpoint

Why doesnt my checkpoint system work?

Hi, im currently trying to get a checkpoint system to work in my game, I have a Kill Volume(as shown in picture 1) that when you touch it, it spawns you back at the beginning, as shown in picture 2! alt text

Which spawns you back here!!! alt text

And when you hit a checkpoint, shown as the other square in picture two, the kill volume should spawn you at the checkpoint(square2) rather than the original spawn point(square 1).



This is my killVolume code, which sends you to the original starting zone

 var dest: Transform; // drag the destination object here
 
 
 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 have this so far as code to spawn me at square two

static var dest: Transform;

function OnTriggerEnter(item : Collider) {

if(item.tag == "Player")

{

"RestartScript".dest.Transform = "Checkpoint1".Transform; } }



It obviously not working, which is where you all come in. Any ideas on what I could change for the checkpoint script? I have it to where it will respawn the player at the original spot(square1) when I die, but when I hit the checkpoint and die, it doesnt spawn me at the checkpoint(square2).

killVolumePic.jpg (421.6 kB)
OriginalQuestion.jpg (355.2 kB)
Comment
Add comment · Show 1
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 fafase · Apr 20, 2012 at 07:31 AM 1
Share

You already posted that question and had answers for that issue 2 days ago. Did you try them?

1 Reply

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

Answer by Flash · Apr 20, 2012 at 12:35 AM

On your "Kill Volume" add a variable called something like "RespawnPosition" of type Transform like so.

 var RespawnPosition:Transform;

Also add a tag to your kill volume called "deathzone" or something similar.

In your checkpoint script write this for the OnTriggerEnter function.

 function OnTriggerEnter(other:Collider){
     var killzone : GameObject;
     killzone = GameObject.FindGameObjectWithTag("deathzone");
     killzone.GetComponent(killVolume).RespawnPosition = transform;
 }

Now when respawning the player (on your kill volume) do.

 function OnTriggerEnter(other: Collider){
     if (other.tag == "Player"){
         // move the player and align it to the dest object:
         other.transform.position = RespawnPosition.position;
         other.transform.rotation = RespawnPosition.rotation;
     }
 }

This will make sure that your kill volume knows at which point to respawn the player and it will also make sure that the kill volume actually spawns the player at that point.

Comment
Add comment · Show 8 · 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 20, 2012 at 03:07 AM 0
Share

0

kk i entered everything in, currently getting this error in the checkpoint script:

Assets/Scripts/Checkpoint.js(4,34): BCE0005: $$anonymous$$ identifier: 'killVolume'.

I double checked and made sure my killVolume had the right tag on it, which is deathzone

here is the script:

function OnTriggerEnter(other:Collider){

var killzone : GameObject;

killzone = GameObject.FindGameObjectWithTag("deathzone");

killzone.GetComponent(typeof(killVolume)).RespawnPosition =transform;

}

avatar image Orggrim · Apr 20, 2012 at 03:14 AM 0
Share

kk tried putting quotes around killVolume, got these errors:

GetComponent requires that the requested component 'String' is inherited or implemented by 'killVolume'. UnityEngine.GameObject:GetComponent(Type) Checkpoint:OnTriggerEnter(Collider) (at Assets/Scripts/Checkpoint.js:4)



NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cache$$anonymous$$eyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) Checkpoint.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Checkpoint.js:4)

avatar image Flash · Apr 20, 2012 at 03:42 AM 1
Share

Well the "killVolume" should be the script that is controlling your kill zone.. If that makes sense. Try removing the "typeof()" and just go with:

killzone.GetComponent(killVolume).RespawnPosition =transform;

I normally don't use Javascript (I use C#) so I may have screwed up the "GetComponent" function in my original answer.

avatar image Flash · Apr 20, 2012 at 04:38 AM 1
Share

You should. Let me explain what the script does line by line.

1: function OnTriggerEnter(other:Collider){ 2: var killzone : GameObject; 3: killzone = GameObject.FindGameObjectWithTag("deathzone"); 4: killzone.GetComponent(killVolume).RespawnPosition = transform; 5: }

LINE 1: This declares the function "OnTriggerEnter" and takes a parameter of type "Collider".

LINE 2: Here we declare a variable of type "GameObject" local to the "OnTriggerEnter" function.

LINE 3: Here we select the object in our scene that has the tag "deathzone" and stores it in the variable we created on line 2. This is why I wanted you to assign that tag to your kill volume.

LINE 4: Now we access the "killVolume" script (That you made and dragged onto the kill volume in the editor) and assign the "transform" of our checkpoint (Where this script is placed) to the "RespawnPosition" variable on the "kill volume" object.

LINE 5: You know this one but here we close the "OnTriggerEnter" function.

Can you try the script above and tell me if it gives you an error again? If it does then I'm pretty sure I know what's wrong. Also remember to actually create the "RespawnPosition" variable on your kill volume.

avatar image Orggrim · Apr 20, 2012 at 04:44 AM 1
Share

wow lol works perfectly now, lol derp move on my part, thxs alot man u rock!

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Checkpoint script problem 1 Answer

Help with SendMessage 1 Answer

How do I randomize the order of spawn points without repeats? 1 Answer

Respawning my AVATAR 1 Answer

Checkpoint system??? 3 Answers


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